How CSS quirks box models and standard box models are used

Source: Internet
Author: User
This time to bring you the CSS weird box model and standard box model how to use, using the CSS weird box model and standard box model of the attention to what, the following is the actual case, take a look.

In an HTML document, each label that is rendered on the page is a box model.

The box model is also divided into: W3C标准的盒子模型 and IE标准的盒子模型 .

As most of the mainstream browser support is the standard box model (standard box model), but also to preserve the weird box style parsing, of course, ie followed by its own standard box model (weird box model)

The two box models are described in two simple examples:

Standard Box Model:

<!--html--><p class= "Box1" >    <p class= "Box2" ></p></p>
<!--css-->.box1{         width:200px;         height:200px;         Background-color:aqua;         padding:30px;        }. box2{         width:200px;         height:200px;         background-color:red;        }

The width and height of the outer box here are: + + + + = 260px.

Weird box model

< add box-sizing attribute--><!--css!--box-sizing properties: border-box (weird box model), Content-box (standard box model)-->.box1{         width : 200px;         height:200px;         Background-color:aqua;         padding:30px;         Box-sizing:border-box;        }. box2{         width:200px;         height:200px;         background-color:red;        }

The width and height of the outer box here are: + 140+ = 200px.

Here is a conclusion:

Standard box model, the total width of a block = width (content width) + margin (left and right) + padding (left and right) + border (left or right)

Weird box model, total width of a block = width (content + border + padding) + margin (left/right)

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

Descendant selectors for CSS

On the layout of CSS Web pages

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.