css3可以通过box-sizing来指定盒模型,它有两个值content-box、border-box
这样就会出现两种情况:
1.box-sizing:content-box 盒子大小为width+padding+border(以前默认的)
2.box-sizing:border-box盒子大小为width
举例说明:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.test1 {
width: 100px;
height: 100px;
padding: 50px;
margin: 50px;
box-sizing: content-box;
background-color: red;
/* 上面是默认值 */
}
.test2 {
width: 100px;
height: 100px;
padding: 50px;
margin: 50px;
box-sizing: border-box;
background-color: green;
}
</style>
</head>
<body>
<div class="test1"></div>
<div class="test2"></div>
</body>
</html>

