Reputation: 19759
The best way to illustrate this question is with...a Fiddle! Before you visit the fiddle, notice there is text behind the grayest element, which is on top of a light gray element that has a border.
There is a main wrapping div (root), and two wrapping divs inside (wrap1 and wrap2). The problem here is that I need the content of wrap2 (highlight) to be behind the content of wrap1 (text), but in front of the background of the root.
This, however, must not change:
The HTML, the elements and wraps should be left untouched. Excluding the order of wrap1 and wrap2 inside root.
The highlight div must keep the absolute positioning.
Styling highlight with background-color
is not an option, the existence of highlight is a must.
PS: the italics reference the id's of <div>
s in the fiddle example, for whomever was too lazy to visit it.
Upvotes: 3
Views: 1333
Reputation: 10429
z-index can be difficult to grasp. I think somebody already answered your question, but if you want to learn more how they work, this is a pretty comprehensive guide:
And also, here is a link where you can try out different z-index and how they are affected by different position properties (the main reason for difficulty)
http://tjkdesign.com/articles/z-index/teach_yourself_how_elements_stack.asp
Upvotes: 0
Reputation: 56634
I was able to display the text in front of the highlight by adding a z-index
to text. (Adding the z-index
to wrap1 also works.) The trick is to remember that z-index
doesn't apply to statically-positioned elements, so you need to give the same div position: relative
.
#text {
position: relative;
z-index: 1000;
}
(Large z-index
because I've been bitten by IE not respecting low values in the past. May or may not still be an issue. ;-)
Upvotes: 3