Undoing Element Expanding in CSS
As a rule, the expansion described in the previous lessons is harmful and you would like to get rid of it. For this purpose, CSS has the box-sizing property. If you specify the value border-box for it, then neither padding nor the border will expand the block:
<div id="elem1"></div>
<div id="elem2"></div>
#elem1 {
width: 100px;
height: 100px;
background: #f1f1f1;
margin-bottom: 20px;
}
#elem2 {
width: 100px;
height: 100px;
background: #f1f1f1;
padding: 25px; /* set indents */
border: 10px solid green; /* set the boundary */
box-sizing: border-box; /* remove extension */
}
:
Try the described box-sizing property yourself.