css - 如何使div低于另一个div

标签 css html margin

我想要 #blue div 在 #green div

下方

#blue div 有 margin-top : -10px;属性

 <style>
    #red{
        width: 400px;

        border: 1px solid red;
    }
    #green{
        width: 100%;
        height: 100px;
        background-color: green;
        border-bottom: 2px solid yellow;
        z-index: 2;
    }
    #blue{
        width: 100%;
        height: 100px;
        background-color: blue;
        border-top: 2px solid brown;
        margin-top: -10px;
        z-index: 1;
    }
    </style>


<div id="red">
    <div id="green">
    </div>
    <div id="blue">
    </div>
</div>

最佳答案

可能在 #blue#green div 和 position:relative 上添加 position:absolute #red div 会做你想做的,因为我怀疑你需要一个在另一个后面。如果他们需要一个接一个,那么也可以在蓝色和绿色上使用相对定位。

关于css - 如何使div低于另一个div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15965200/

相关文章:

html - 为什么 1px 的边框会抵消 100px 的 margin-top 并杀死滚动条?

jquery - jQuery 中的左边框宽度返回 NaN

css - 纯 CSS dropup-menu : I have the basics functioning, 但如何让二级 li 元素显示为内联而不是相互叠加?

javascript - 全部居中并根据数据长度调整excel列

html - 如何在多个屏幕尺寸上水平对齐按钮

jquery - 如何在用作所见即所得编辑器的 DIV 中添加边距准则?

html - 通过 css 创建半径

css - 设置 border-right 时删除 border-top gap

html - Mozilla 一直将 contenteditable 范围内的光标位置发送到开头

r - 如何从ggmap中删除边距