[One day learning a CSS3 attribute] One: box-sizing, css3box-sizing

Source: Internet
Author: User

[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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.