【发布时间】:2016-11-30 10:40:19
【问题描述】:
我有一个包含一个标题和两个其他框的框。标题顶部有负边距,因此它呈现在框外。在除 Firefox 之外的所有浏览器中,标题都正确地拉出其兄弟框,但在 Firefox 中,框保持在原位。
如果我从盒子中移除浮动,但它们确实向上移动。除了给盒子负边距顶部之外,还有其他解决方法吗?
div {
background: red;
padding: 2rem;
margin-top: 8rem;
box-sizing: border-box;
}
div:after {
display: table;
content: "";
clear: both;
}
div div {
background: green;
margin: 0 0 2rem;
width: 45%;
float: left; /* Remove this and float: right below and it works in FF */
}
div div + div {
float: right;
}
h2 {
margin-top: -8rem;
}
<div>
<h2>
Hello
</h2>
<div>
These boxes also render outside the red one.
</div>
<div>
In every browser except Firefox.
</div>
</div>
【问题讨论】:
标签: html css firefox css-float margins