我有 2 个 div
,并希望第一个定义的 div
(称为 befront
)位于 div 的前面
紧随其后定义(称为 beback
)。
使用 position: absolute;
破坏了设计,所以我只想使用不起作用的 z-index
。
我使用了以下 CSS,但没有成功:
#befront {
width:100%; height:20px; background:red;
/* I expect that the rex box be in front of the yellow box*/
margin-bottom:-20px;
z-index: 1000;
}
#beback {
width:100%; height:20px; background:yellow;z-index:1;
}
最佳答案
你能不能只加上“position: relative;”到你的“#befront”?
#befront {
width:100%; height:20px; background:red;
/* I expect that the rex box be in front of the yellow box*/
margin-bottom:-20px;
z-index: 1000;
position: relative;
}
#beback {
width:100%; height:20px; background:yellow;z-index:1;
}
z-index 要求您的元素定位才能正常工作。
参见 here
关于css - 将前一个(第一个 defibed)div 放在下一个(第二个)div 的默认位置前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17915138/