Displaying a div on top of another without using z-index - html

I've created custom drop down menus that have one <div> holding the current value and acting as a <select> field and another below it that gets displayed when the top one is clicked, holding all the <option> values.
The design requires the bottom <div> to position slightly below the upper one (weird rounded corners, etc) so I used z-index to achieve that. It all works until the moment I have two drop down menus close to each other. If you click the upper one the drop down option list is displayed but it goes below the second drop down menu as well which is highly undesirable. Here's simplified version in a jsfiddle:
jsFiddle
As you can see, the first drop down menu is fine but the second one is hidden below the third one. Any ideas how can I achieve this so the second menu works as well? May be without using z-index somehow?

First, wrap each menu in an element. I used a div.container.
Since only one menu is going to be open at a time, simply changing the z-index of the .major and .minor elements in each container (on hover in my example) works correctly:
.major {
position: relative;
width: 100px;
background-color: red;
z-index: 1;
}
.minor {
position: absolute;
width: 150px;
background-color: blue;
padding-top: 10px;
margin-top: -10px;
z-index: 0;
display: none;
}
.container:hover .major {
z-index: 5;
}
.container:hover .minor {
display: block;
z-index: 4;
}
.moveup {
margin-top: -25px;
}
<div class="container">
<div class="major">
First one fine
</div>
<div class="minor">
Option part goes here Option part goes here Option part goes here
</div>
</div>
<br />
<br />
<br />
<br />
<div class="container">
<div class="major">
Second menu
</div>
<div class="minor">
Option part goes here Option part goes here Option part goes here
</div>
</div>
<div class="container">
<div class="major">
Third menu
</div>
<div class="minor">
Option part goes here Option part goes here Option part goes here
</div>
</div>

I'm not 100% sure what you mean, but if I'm not wrong, the solution should be to wrap the .major and .minor divs so they don't overlap each other, like so:
<div class="dropdown">
<div class="major">
First one fine
</div>
<div class="minor">
Option part goes here
Option part goes here
Option part goes here
</div>
</div>
See my fork of your JSFiddle: https://jsfiddle.net/jk1dn4yx/

Related

Click trough overlay element

<div class="box">
<div class="top">
</div>
<div class="bottom">
<img src="//placehold.it/300x300">
</div>
</div>
.bottom{
position: absolute;
bottom: 0;
}
I got 2 blocks, top and bottom. In bottom block there is an image that should overlay top block in one place. it overlays Ok but I can't click on element from top block cause browser think i click on bottom. How can it be resolved?
Add
pointer-events : none;
to your .bottom element.
https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events

Add letter to the right side without pushing text to left

I have this HTML here:
<div class="last_img">
<p>Galutinė žetono išvaizda:</p>
<span class="zetin11">A</span>
<span class="zetin12">A</span>
<span class="zetin13">A</span>
<span class="zetin14">A</span>
<span class="zetin15">A</span>
<img class="last_img_img" src="images/img1.png" alt="">
</div>
When I write text, the text in span move to the left, so it goes outside of image. How can I only add letter to the right side, without moving text to the left ?
This is my css of zetin11:
position: relative;
top: -125px;
right: -79px;
font-family: Courier;
font-size: 18px;
From the Question what I understood is that you want to pull the A's to the right without moving the paragraph. If that's the Case then here is a
I just used the
span{
float: right;
}
Working Fiddle: https://jsfiddle.net/rittamdebnath/fdhj1u6s/
I would do this as follows :
HTML
<div class="last_img">
<p>Galutinė žetono išvaizda:</p> <br />
<div class="imagecontainer">
<img class="last_img_img" src="https://i.imgur.com/I86rTVl.jpg" alt="" />
</div>
<!-- Seperate them into different classes to style them later on -->
<div class="spancontainer">
<span>A</span>
<span>A</span>
<span>A</span>
<span>A</span>
<span>A</span>
</div>
</div>
CSS
.last_img{
width: 100%;
}
.imagecontainer{
float: left;
}
.spancontainer{
float: right;
}
Click Here for JS Fiddle Example
Recap: I separated both items into different divs so that I will take control over the divs using CSS.
I included a class for the first div named image container which is set to float left so that the image will stick to the left
and another div spancontainer which is set to float right so that it will stick to the right near the image.
I like setting a global div class so that I can encapsulate all the others inside it and have control on giving the global class also a specific width in the page itself... in such case I set it to 100% and I used the name you used 'last_img'
I also removed the zetin classes as you won't be needing them as long as you aren't going to style each span seperately ;)
Hope this helps ;)

make header image to partially overlap fixed nav bar with working buttons

There are two main elements on the page: 'header image' and 'navbar'. The image overlaps the navbar partially using margin.
By default it works fine because of some trick which I don't know.
Image ovelaps the navbar but links in navbar are still working in the area where image is transparent
However once navbar is made fixed (position:fixed after scrolling, by affix plugin) this trick doesn't work anymore - navbar overlaps the image.
My html is the following:
<div class="container brand-img-container">
<img class="brand-img" alt="" src="IMAGEWHICH OVERLAPS PARTIALLY" />
</div>
<div id="nav-wrapper" class="container">
<div class="row">
<div id="nav" class="navbar navbar-static span4">
<div class="navbar-inner">
<ul class="nav pull-left">
<li>Button</li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<h2> R <h2>
</div>
CSS is the following
#nav.affix {
position: fixed;
top: 0;
}
.brand-img-container {
position: relative;
margin-bottom: -80px;
}
You can find it here with the picture (base64)
http://jsfiddle.net/5qYK8/9/
When I try to play with z-index, the image fully overlaps the navbar even in default case and links are not working at all.
You can find it here
http://jsfiddle.net/5qYK8/8/
Is it possible to make image (part of red cross) to overlap the navbar in fixed and not fixed cases with working Button?
Can someone at least explain why Button is working in first case when image does overlap it?
Because you have 1 image rolling over the link in the navigation at at one point, its going to cover the link, so you are going to have to create another link in a fixed <div> using your same jquery script. The link will be transparent, but the spot will be clickable with whatever link you place in it
You will need to create another <div> container, then place <a> link around a <div>, like this:
<div id="toplayer">
<a id="nav1" class="link" href="#"><div class="inner"></div></a>
</div>
You will also have to duplicate the selector ID below and rename it to something like this example.
#nav1.affix {
position: fixed;
top: 0;
z-index: 0;
}
Your CSS will need to have a z-index higher than the div containing the image. In my example, I have made the background blue so you can see it move while testing it.
#toplayer{position:relative;width:85px;height:40px;}
.inner{width:85px;height:40px;background:blue;}
.link {width:85px;height:40px;}
Here is a fiddle with a blue background so you can see it working. Here is a fiddle without the blue so you can see what it should look like.

How do i stack divs next to and on top of eachother?

I don't know much about html or css but I have done this much;
I want to stack divs so it looks like this (please excuse the bad drawing) ;
I have googled how to and tried different thing but the likes/dislikes boxes always end up not moving or move to the very left/very right.
<div style="float:left;width:300px;height:350px;text-align:center;">
<div style="float:left;width:500px;height:200px;text-align:center;">
<div id="wrapper">
<div style="align=center;">
<div id="first">1</div>
<div id="second">2</div>
These are th three divs I have.
First one has links [the add/message etc]
Second one has "thelastgecko" and profile text.
And I am trying to use the last box for likes/dislikes but whatever im doing it isn't working.
You usually use one "huge" div, set it below 1024 pixels wide so old screens can view it and then you usually center it in the middle of the screen. Then inside of that big div you put the "add me - message me - gallery" with a "float:left" or "position:absolute" I prefer the latter. then you make another div containing the "The last gecko" + dislikes & likes and center that div, then after that I would make another div and either do a "float:right" or a "position:absolute; left:'huge width minus this ones width".
I did write everything in text and readable since giving the code away doesn't teach as well.
But in case you still didn't get it, here's my idea:
<html>
<head>
<style>
body{margin:0px;padding:0px;width:100%;height:100%;}
#container{width:900px;margin:auto;margin-top:200px;}
#add_me,#dislike_text{position:absolute;width:200px;background-color:#ace;}
#last_gecko,#holder{margin:auto;width:500px;background-color:#eca;}
#likes,#dislikes{float:left;width:250px;display:block;background-color:#cae;}
#dislikes{background-color:#cea;}
#dislike_text{margin-left:700px;background-color:#eac;}
</style>
</head>
<body>
<div id="container">
<div id="add_me">add me<br>message me<br>wuts going on</div>
<div id="dislike_text">dislike text</div>
<div id="last_gecko">
Last Gecko
<div id="holder">
<div id="dislikes">dislikes</div>
<div id="likes">likes</div>
</div>
</div>
</div>
</body>
</html>
Made it workable, it will at least show you in what direction to move, It might not be the best way but it is my way.
You could do something like this: http://jsfiddle.net/jAKgd/
CSS
#wrapper {
width: 800px;
}
#leftColumn {
float: left;
height: 800px;
width: 200px;
margin-right: 5px;
}
#leftColumn a {
display: block;
}
#rightColumn {
width: 100%;
}
#contentDislike,
#contentLike {
display: inline-block;
width: 250px;
}
Obviously the height/widths can be changed to meet your needs. I was just doing a quick example.
HTML
<div id="wrapper">
<div id="leftColumn"> Link
Link
Link
Link
Link
</div>
<div id="rightColumn">
<div id="contentTop">
<img src="/images/image_name.jpg" alt="image text here" />
<p>THIS IS WHERE YOUR PROFILE TEXT WOULD SHOW. IT CAN EXPAND HEIGHT AS NEEDED.</p>
</div>
<div>
<div id="contentDislike">DISLIKE CONTENT HERE</div>
<div id="contentLike">LIKE CONTENT HERE</div>
</div>
<div>YOUR LOWER TWO COLUMNS WILL GO IN THIS DIV</div>
</div>
</div>
It's a bad way of design to use floats to place divs at some place.
It's a much better way to use, for example, a flex layout.
But this is not supported by all browsers (But nearly. If you can, take this option).
Another solution is this one:
Use the width option. You set the width of any div of your html to a fixed number, in percent, of course. Watch this example
But if you do this, you will have to pay attention for very large and very little screens, I think you would have to write alternative css style sheets which are working with (max-width) and (min-width).
And there is another solution: the gridlayout. It is part of the standards since 2013 (I think) but it's not well supported yet. But maybe in future.
Hope I could help

CSS help to create a box that I have overlay layers on top of each other

Here's what I'd like to learn how to do with CSS.
I want a box:
I want the cards to be stacked directly on top of each over flat... Not vertically. that way I can use jQuery to tell the browser which card to show, and not have to reinject all the content.
I think GMAIL does something like this... You see an inbox, when you click a message it places the message on top of the inbox, keeping the inbox in the background.
Ideas?
Another way to distinguish a visible div from the hidden ones, would be by using e.g. the selector :first-child. Here's an example where you hide one div by changing it's position within the DOM tree and the CSS only let's the first child be visible.
<html>
<head>
<style type="text/css">
#container div { display: none; width: 400px; height: 250px }
#container div:first-child { display: block; }
</style>
<script type="text/javascript">
function hide(div)
{
var container = document.getElementById("container"); /* Or use jQuery */
container.appendChild(div);
}
</script>
</head>
<body>
<div id="container">
<div style="background-color: red" onclick="hide(this)">Click to hide</div>
<div style="background-color: blue" onclick="hide(this)">Click to hide</div>
<div style="background-color: yellow" onclick="hide(this)">Click to hide</div>
</div>
</body>
</html>
i'm not sure i understand your question,
but to have a bunch of divs in the same spot but different depths, you should:
give those divs the position attribute (absolute or relative, depending on your needs) to place them in the same spot
use z-index, to give them different depths to show and hide them.
Use JQuery to change the z-index as needed
It sounds like what you're after is to load all this content directly and then using Jquery to just show and hide stuff.
CSS:
.box {width: 100px; height: 100px;}
.box.hidden {display: none;}
HTML:
<div class="box"><!-- your default content --></div>
<div class="box hidden"><!-- your hidden content --></div>
<div class="box hidden"><!-- your hidden content --></div>
Then just use JQuery to show the <div> you want visible, and hide the others. It will behave as if they were all stacked on top of each other.