CSS quirks box model and standard box model example detailed

Source: Internet
Author: User
In the HTML document, each page is rendered in the label is a box model, this article mainly introduces the detailed CSS box model and standard box model, small series feel very good, and now share to everyone, but also for everyone to do a reference. Follow the small series together to see it, hope to help everyone.

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)

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.