I have the following setup:
<div style="z-index: 10">
<div>Whatever</div>
</div>
<div style="z-index: 9">
<div><div>Haaaleluia</div></div>
</div>
Of course... I oversimplified the setup but that's the main idea. The "whatever" div is overlapped by the "Haaaaleluia" div. Of course because the first parent has bigger z-index "whatever" is visible and "haaaleluia" is not.
Without changing the setup (and to be clear that includes keeping the parents z-indexes), how can I make "Haaaaleluia" to be on top?
For those asked for print here it is... also thank you for help:
The big bad map is the second div.
The tutorial is the first div.
The panel with orders is child of the map. I need it to be on top. If I set whole map on top, the tutorial is not visible any more. If I keep the map behind the orders panel is not visible any more.
Without changing the locations,
z-index
, or rearranging any of the elements, the only way I can think of that would allow thediv
underneath to appear would be to either change thevisibility
,display
oropacity
of thediv
overlapping the one you want to see.That is, use one of the following CSS styles on the parent
div
of "Whatever":You're basically asking to display an element above another element that has a higher
z-index
, which defeats the purpose of having az-index
. If you're trying to control how elements overlap, it really should be done withz-index
. I would suggest you rethink how your elements are organized (maybe move the "Haaaleluia"div
outside of its parent and assign it its ownz-index
). Otherwise, I might suggest you consider creating a duplicate of "Haaaleluia" to display above "Whatever", which may or may not suit your situation.Edit: Looking at the image you've provided, changing the parent of the order box to the parent of the tutorial div may work for you. Here is a demo using jQuery that may help illustrate the point - just change the hover event to whatever it is that starts the tutorial. Another option may be to clone the order box to lay on top of the one below, but with a higher
z-index
(so that the user only sees one, but the clone overlaps everything else). This is assuming that your map div is positioned either absolutely or relatively. Hope that helps.Added colour to the div's to demonstrate the layering:
Nice design.
Ok so I'll first say that I believe the solution to your layering problem, as others have already suggested, is moving that box outside of its parent (the map).
But you set some constraints, so I'll try to break as few as possible. I don't know how to do this without breaking any of your constraints. Z-index is inherited (again, others have pointed this out), so you can't break out of your parents' layer with only that tool.
So here's one way you could get the same effect, using javascript. It's ugly, and might cause you more headaches later, but it should at least work:
If you're using jQuery, you can get elements' position relative to the document with the
.offset()
function. After that it's fairly simple:That script works for me on this markup:
With these styles:
And here's a handly jsfiddle demo.
This is just an idea which may work.
$(element which you got).attr("style", "position: absolute; z-index: 12;")
The style will be applied to the small element and it will be visible on the red box.
In short: you can't. It's not possible to have a child of a parent element with a
z-index
lower than a sibling, and give that child a higher z-index value than the parent's sibling, as the inherited z-index is relative to the parent (see this question for someone coming up against the same thing).However, depending on your setup, you can remove the z-indices completely, and let the browser place your top
div
above the one below. You could then play around with giving just the children az-index
value.