[One day learning a CSS3 attribute] One: box-sizing, css3box-sizing
Box-sizing is used to change the CSS box model and change the calculation mode of element width and height.
The value of box-sizing is as follows:
box-sizing: content-box | padding-box | border-box
The default value is content-box, which corresponds to the standard box Model Calculation Method in CSS2.1 specifications. That is, width and height indicate the width and height of the content area, excluding the border, inner margin, and outer margin;
Padding-box according to the MDN statement, it is still an experimental attribute. width and height include the content area and padding, excluding the border and external data;
Border-box includes the padding and border, excluding the margin. This is the box model used by Quirks mode.
Example (from MDN)
1 /* support Firefox, WebKit, Opera and IE8+ */2 3 .example {4 -moz-box-sizing: border-box;5 box-sizing: border-box;6 }
Impact on JS
According to MDN:
By window. box-sizing is not considered when getComputedStyle gets the height. At least Firefox 18 (bug 520992) and Internet Explorer 9 are like this, But Chrome 24 is not (not tested by other browsers ). note that IE9 currentStyle cannot return the correct height value.
I have not tested Firefox 18 or later versions.
Return values of. width () and. height () in jQuery
The support for box-sizing is added after jQuery 1.8, but this is also related to whether the browser supports box-sizing. In short, after jQuery 1.8 ,. width () and. height () always returns the width and height of the content area. See the following code:
<!DOCTYPE html>
The result is as follows:
- Internet Explorer 6/7: 500
- IE8/9/10: 480
- Safari5/6: 480
- Chrome21/Firefox14: 480
IE6/7 does not support box-sizing, And the content area width is 500, so the output value is also 500. other browsers that support this attribute, the content area width minus the values of padding and border is changed to 480.
The. outerWidth () and. outerHeight () methods in jquery are not affected.