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

标签 css html z-index

我有 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/

相关文章:

html - 具有不同缩进的元素符号列表

jquery - 本地托管站点的文件路径

html - 是否可以根据一行中文本的长度来减小 div 的宽度?

css - 移动端图片覆盖表单

c# - itextsharp 在表格单元格中的圆形图像上添加文本

html - 自动嵌入 YouTube 视频 [上一个]

css - ie7 css html 填充问题

html - 如何加快嵌入式 youtube 视频和 woff 文件的加载速度

html - Summernote 所见即所得在外部弹出窗口中无法正确显示

css - 在滚动条上叠加 div