【发布时间】:2014-01-16 14:53:00
【问题描述】:
我有一个带填充的<div>。我已将其设置为height: 0,并将其设置为overflow: hidden 和box-sizing: border-box。
HTML
<div>Hello!</div>
CSS
div {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
height: 0;
overflow: hidden;
padding: 40px;
background: red;
color: white;
}
据我了解,这应该会使 <div> 消失。
但是,它仍然可见(在我的 Mac 上的 Chrome 31 和 Firefox 25 中)。尽管box-sizing 声明,height 声明似乎并未应用于填充。
这是预期的行为吗?如果是这样,为什么? The MDN page on box-sizing 似乎没有提到这个问题。
据我所知,the spec 也没有——在我看来,当设置了box-sizing: border-box(或者实际上是padding-box)时,宽度和高度都应该包括填充。
【问题讨论】:
-
是的,如果您想在现实世界中使用这种 div,您应该在其中制作额外的 wrapper DIV 并将填充移动到它。
标签: css