box-sizing属性为三个值:content-box,border-box,inherit
值的功能:
content-box:width不包含border和padding
border-box:width包含border和padding
inherit:继承父元素的box-sizing值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.content-box{
box-sizing:content-box;
-moz-box-sizing:content-box;
width: 100px;
height: 100px;
padding: 20px;
border: 5px solid #E6A43F;
background: blue;
}
.border-box{
box-sizing:border-box;
-moz-box-sizing:border-box;
width: 100px;
height: 100px;
padding: 20px;
border: 5px solid #3DA3EF;
background: yellow;
}
</style>
</head>
<body>
<div class="content-box"></div>
<div class="border-box"></div>
</body>
</html>蓝色正方形
黄色正方形
本文介绍了CSS中box-sizing属性的三种值:content-box、border-box和inherit,并通过实例展示了它们的效果。content-box使得宽度不包括边框和内边距;border-box则包含边框和内边距在宽度内。
1654

被折叠的 条评论
为什么被折叠?



