我想让这个购物车的 div 跟随用户的视口(viewport) (http://testshop.michaelkenji.com/),所以我尝试简单地将 div { position:fixed} 注入(inject)到它的样式表中,它起作用了,但是我在这里要问的是一些复杂的问题.
问:给定两个固定元素,它们发生碰撞,哪个会在上面? 问:如何使一个元素成为绝对的“顶部”(仅使用 css)
最佳答案
当你想重叠顶部的元素时,你应该使用更高的 z-index 值,例如:
div{
position: fixed;
top: 0;
width: 100%;
z-index: 1;
}
div{/*this div will be on top layer of previous div*/
position: fixed;
top: 0;
width: 100%;
z-index: 2;/*because of higher z-index*/
}
关于html - 如何使固定元素位于另一个位置固定元素之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27495772/