The box-sizing
property controls how
the browser handles the sizing properties, or how to calculate
width and height of an element.
The box-sizing
CSS property sets
how the "box model" is handled.
For example, we have
.element { width: 100px; padding: 20px; border: 5px solid black; }
The resulting box is 150px wide. if the box-sizing model is content-box.
We can change the box-sizing property to padding-box
where the box would be 110px wide with 20px of padding on the inside,
or border-box
where the box would
be 100px wide with 10px of border and 20px of padding on the inside.
box-sizing: content-box|border-box|initial|inherit;
box-sizing |
Yes | 8.0 | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<head>
<style>
div.container {<!-- ww w. j a v a 2s.co m-->
width: 30em;
border: 1em solid;
}
div.box {
box-sizing: border-box;
width: 40%;
border: 1em solid blue;
float: left;
}
</style>
</head>
<body>
<div class="container">
<div class="box">This div occupies the left half.</div>
<div class="box">This div occupies the right half.</div>
<div style="clear:both;"></div>
</div>
</body>
</html>