css - Firefox 解释 margin-bottom 错误。也许是一个错误?

标签 css firefox margin

这里是重现失败的最低版本:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>title</title>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <style type="text/css">
        .clear{clear:both;}
        .col{float:left;}
        .row{margin-bottom:30px;background-color:red;}
    </style>
</head>
<body>
    <div class="row">

        <div class="col">Lorem Ipsum</div>
        <div class="clear"></div>
    </div>
</body>
</html>

这是 Firefox 的 Bug 或者我误解了什么。 编辑: 忘记解释问题了。当我将 .row 的 margin-bottom 与 .col 中的 float 结合使用时,该元素将被下拉以获得与 .row margin-bottom 具有相同的值

最佳答案

我不完全确定为什么 Firefox 在这里的行为与其他浏览器不同。这与 collapsing margins 有关.

但是,您可以通过以下方式轻松修复它(在 Firefox 中不会向下移动,浏览器之间保持一致):

  • 正在添加 overflow: hidden.row作为清除 float 的替代方法。

然后您可以删除 <div class="clear"></div>因为不再需要它。

关于css - Firefox 解释 margin-bottom 错误。也许是一个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5272091/

相关文章:

Python + Selenium,GeckoDriver 打开 Firefox 浏览器然后什么都不做

css - Firefox 3 为显示 :inline-block 的跨度添加间距

html - CSS margin 恐怖; Margin 在父元素之外添加空间

css - 清晰的两个容器中的边距未被应用

html - 边距占用空间但没有背景

javascript - wordpress 中的自定义菜单无法正常工作,谁能告诉我为什么?

css - 响应式 2 张图像超过另一张图像问题

html - 强制数据角色 ="page"无论方向如何,始终执行 100% 高度

javascript - Document.oncontextmenu,组件不可用(firefox)

css - 设置表格列宽