Jos*_*hua 2 html javascript css
我的网站顶部有一个div,它是100%宽,处于绝对和固定的位置.它的代码如下:
div.header{
height: 60px;
width: 100%;
position: absolute;
position: fixed;
top: 0px;
left: 0px;
background-color: #eeeeee;
}
Run Code Online (Sandbox Code Playgroud)
现在一切都有效,但当用户向下滚动时,网站内容会显示在此后面.有没有办法可以防止这种情况发生?
去掉 position: fixed;
应该是这样的
div.header{
height: 60px;
width: 100%;
position: absolute;
top: 0px;
left: 0px;
background-color: #eeeeee;
}
Run Code Online (Sandbox Code Playgroud)
如果你想让它固定而不是删除position:absolute.两者都无法合作.
你有position:absolute和fixed两个在一起,但fixed会覆盖位置,因为它是绝对的.
现在,如果你想要出现在其他元素之上的任何元素并且它有一个位置:绝对或固定你可以使用z-index,更高的z-index元素将掩盖更低的z-index元素.