html - 当我使用 clear :both 时,margin-top 不工作

标签 html css

html,

<div id="content">
    <div id="left">left</div>
    <div id="right">right</div>
    <div id="bottom">bottom</div>    
</div>

CSS,

#content {
    border:1px solid black;
}
#content > div {
    height:100px;
    box-sizing:border-box;
    -moz-box-sizing:border-box;
}
#left {
    float:left;
    width: 50%;
    border-right:1px solid black;
}
#right {
    float:right;
    width: 50%;
}
#bottom {
    border-top:1px solid black;
    clear: both;
    margin-top: 50px;
}

演示

http://jsfiddle.net/saBE2/1/

我想在底部div的左右div之后留出一些空间

但如果我使用 clear:both,margin-top 将不起作用。

有什么好主意吗?

最佳答案

清除左、右后的 float 。

尝试:

HTML:

<div id="content">
    <div id="left">left</div>
    <div id="right">right</div>
    <div class="clr"></div>
    <div id="bottom">bottom</div>
</div>

CSS:

#bottom {
    border-top:1px solid black;
    margin-top: 50px;
}
.clr{clear: both;}

Updated fiddle here.

关于html - 当我使用 clear :both 时,margin-top 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20536191/

相关文章:

html - 使用纯 css 动画 html 选项卡内容以像轮播一样移入/移出

javascript - 下拉菜单在 Firefox 中运行良好,但在 Chrome 中不可靠

javascript - 在页脚上粘贴 div 元素

html - Service Worker 是否会竞争带宽?

javascript - 循环遍历元素列表以查看它们是否处于事件状态

CSS "d"路径 - 属性在 Safari、FireFox 中不起作用

css - 使用 CSS 保持 div 的纵横比,并设置最大高度

javascript - 如何在没有额外库的情况下将 div 保存为图像?

javascript - 图像 slider 全屏

javascript - document.getElementById.value 不起作用