简体   繁体   English

将div放在页面顶部,但在其他div之下

[英]Keep a div at top of page, but beneath other divs

I want to have a div with a background image at the top of my website. 我想在我的网站顶部添加一个带有背景图片的div。 But when the page is scrolled the div should go underneath the other divs (while still at the top of the page) and not on top of them (as fixed positioning would). 但是,当滚动页面时,div应该位于其他div的下方(虽然仍位于页面顶部),而不是位于其顶部(如固定位置一样)。
I guess its not possible with CSS? 我想用CSS不可能吗? But javascript/jquery? 但是javascript / jquery?

Try setting your top bar/image to a lower z-index. 尝试将顶部栏/图像设置为较低的z-index。

z-index: -1;

See example at http://jsfiddle.net/a6zdfewx/ 请参见http://jsfiddle.net/a6zdfewx/

Note: If you have a background on your site (set in the body) this will go behind it and will not be viewable. 注意:如果您的网站具有背景(设置在正文中),则该背景将位于其后面,并且将不可见。 You'd need to push forward other elements with something like z-index: 2 for all elements except this which would then be z-index: 1 . 您需要为所有元素使用诸如z-index: 2类的其他元素来推进,除了z-index: 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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