1. Standard box model The
standard box model is
also called W3C box model. Now most browsers use the standard box model.
In standard mode, the total width of an element = width(content)+padding( Left and right) + margin (left and right), the height of the element is the same.
as the picture shows:
2. IE box model The
standard box model is also called the weird box model. The browsers before IE6 adopt the weird box model by default
. The height of the border+padding+content) element is the same.
as the picture shows:
Standard box model and IE box model, the code examples are as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
#ieBox{
width: 200px;
height: 200px;
padding: 20px;
margin: 10px;
border:5px solid rgb(0, 255, 234);
box-sizing: border-box;
/* 加上 box-sizing: border-box; 后可以将div盒模型设置为IE盒模型*/
background: greenyellow;
}
#Box{
width: 200px;
height: 200px;
padding: 20px;
margin: 10px;
border:5px solid rgb(0, 255, 234);
box-sizing:content-box;
/* 加上 box-sizing: border-box; 后可以将div盒模型设置为标准盒模型*/
background: red;
}
</style>
</head>
<body>
<div id="ieBox">
IE盒模型
</div>
<div id="Box">
标准盒模型
</div>
</body>
</html>