有一个padding为30px,宽和高为100px的
元素。box-sizing属性被设置为border-box。当尝试将宽度和高度设置为零时,它不起作用。元素保持60px X 60px 的尺寸(即使overflow属性设置为hidden)。
这是怎么回事?有没有办法使宽度和高度为零,包括padding,使其完全折叠?
.test {
padding: 30px;
width: 400px;
height: 400px;
box-sizing: border-box;
background-color: orange;
overflow: hidden;
}
/* Setting width and height to zero. */
.test {
width: 0;
height: 0;
}
<div class="test"></div>
<p>Have a div with padding of 30px and width and height of 100px. Box sizing is set to border box. When trying to set the width and height to zero, it does not work. Element stays at 60px X 60px dimensions. (Even with the overflow set to hidden).</p>
<p>Any idea what's going on here? Is there any way to make the width and height to zero including the paddings, so that it collapses completely?</p>
display:none
呢?你能告诉我需要使用这个的场景吗? - Suresh Ponnukalaipadding:0
。 - Suresh Ponnukalai