我有两个父元素,里面有 3 个子元素。( #grandParent>#parent>#children*3
)grandParent
具有设定的高度和宽度,并parent
应用了填充。所有元素都有box-sizing: border-box
.
应用border-box
后,填充应该children
变小,但相反,它会将其向下推,并保持其大小。children
为什么应用填充时不会变小?
JSFiddle
* {
box-sizing: border-box;
}
#grandParent {
width: 34px;
height: 34px;
}
#parent {
padding: 30px 5px;
}
.children {
background: black;
height: 3px;
width: 100%;
margin-bottom: 6px;
}
#reference {
background-color: orange;
width: 34px;
height: 34px;
}
<div id="grandParent">
<div id="parent">
<div class="children"></div>
<div class="children"></div>
<div class="children"></div>
</div>
</div>
<div id="reference"></div>