CSS3 The number in the table represents the version number of the first browser that supports the property. Immediately after the number. Attribute Box-sizing 10.04.0-webkit- 8.0 29.02.0-moz- 5.1 3.1-webkit- 9.5 By default, the width and height of an element are calculated as follows: Width + padding + border = actual width of the element Height + padding + border = actual height of the element This means that when we set the width/height of the element, the actual height and width of the element will be larger (because the border and innermargin of the element will also be calculated in the width/height). This is a smaller box (width is 300px, height is 100px). This is a larger box (width is 300px, height is 100px). The above two Example In this way, if you want to get the smaller box and include the inner margin, you have to consider the width of the border and the inner margin. CSS3’s CSS3 If set on the element The two div are now the same size! Rookie tutorial! Here are two < div > elements to add Example From the result point of view The following code allows all elements to display the size in a more intuitive way. Many browsers already support All elements use the Example
box-sizing
Property can be set
width
and
height
properties include padding (inner margin) and border (border). 8.19.1. Browser support ¶
-webkit-
or
-moz-
specifies the prefix for the browser. 8.19.2. Do not use the CSS3 box-sizing attribute ¶
<div>
although the width of the element is the same as the height setting, the actual size of the display is not the same because the
div2
inner margin is specified:.div1{
width:300px;
height:100px;
border:1px solid blue;
}
.div2{
width:300px;
height:100px;
padding:50px;
border:1px solid red;
}
box-sizing
attributes solve this problem very well. 8.19.3. Use the CSS3 box-sizing property ¶
box-sizing
attribute in an element’s
width
and
height
Contains padding (inner margin) and
border
.
box-sizing:
border-box;
then
padding
and borderare also included in the
width
and
height
:
box-sizing:
border-box;
a simple instance of the property..div1{
width:300px;
height:100px;
border:1px solid blue;
box-sizing:border-box;
}
.div2{
width:300px;
height:100px;
padding:50px;
border:1px solid red;
box-sizing:border-box;
}
box-sizing:
border-box;
the effect is better, which is exactly what many developers need.
box-sizing:
border-box;
(but not all.-that’s why.
input
and
text
the width after the element is set to width: 100%; is not the same.
box-sizing
is more recommended:\*{
box-sizing:border-box;
}