css - 包装器 div 高度为 0,内部有 float 元素

标签 css html css-float

我有一个包装器 <div>其中包含两个内部 <div> s 是 float 的。

<div class="outside" style="border:1px solid #555;">
  <div class="inside" style="float:left; width:40px;">CONTENT</div>
  <div class="inside2" style="float:left; width:40px;">CONTENT</div>
</div>

问题是包装器 <div>宽度为 80px,因为两个内部 <div>每个都是 40px。但总是 wrapper <div>0px高度使边框在顶部看起来像一条线。

所以我把两个内<div><table> 里面.它运作良好。但是如何在不使用 <table> 的情况下避免这个问题? ?

最佳答案

在父级上设置overflow: hidden

<div class="outside" style="border:1px solid #555;overflow:hidden;">
  <div class="inside" style="float:left; width:40px;">CONTENT</div>
  <div class="inside2" style="float:left; width:40px;">CONTENT</div>
</div>

关于css - 包装器 div 高度为 0,内部有 float 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10724513/

相关文章:

CSS - 为什么隐藏 flexbox 的开始?以及如何解决保持元素居中?

html - 如何让 float 的 div(宽度未知)保持在一行上

html - 在包含 float 子 div 的父 div 中水平滚动

html - 固定导航栏,白色间隙,为什么?

javascript - CSS margin-left 在 Chrome 扩展中被打破

javascript - 如何让 JavaScript 函数应用的类一直运行到窗口关闭(网页设计)

html - css根据图像宽度向元素添加/删除填充

jquery - 使用 jQuery 属性以开头时如何获取 ID 的其余部分

javascript - iOS 8 : blank gap at bottom of full screen Safari home screen page

html - 使用 css 定位 HTML 元素