gpt4 book ai didi

css - 将前一个(第一个 defibed)div 放在下一个(第二个)div 的默认位置前面

转载 作者:太空宇宙 更新时间:2023-11-04 14:45:17 44 4
gpt4 key购买 nike

我有 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;
}

jsfiddle is here

最佳答案

你能不能只加上“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/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com