简体   繁体   中英

Relatively positioned element in front of fixed element

Currently I have a structure that looks like this:

<div id="header">
</div>
<div class="hook">
</div>
<div class="navbar">
</div>
<div class="content">
</div>

where the header is positioned absolutely on top, the hook is fixed, navbar positioned absolutely, and the content is positioned relatively. How can I get the hook to appear behind everything as you scroll? Currently my only trouble is with getting the content to appear in front; positioning it absolutely does the trick, but I'd like to keep it relative if possible.

You can combine position: relative and z-index: something-bigger-than-one . Unless I'm misunderstanding you, this should do the trick?

Here's a fugly demo :)

http://jsfiddle.net/bvaughn/mopeu8Lw/

By using the CSS operator;

z-index: n;

You can set its "layer", I always picture these almost like a sandwhich, I believe (but don't quote me on this), I think the way layering works by default is standard stacking, until you define them. I hope this image helps you;

You can see here that the blue element would sit on top of everything, followed by the red element, and then the black element.

http://i.stack.imgur.com/pd8iH.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM