CSS box model full explanation, weird mode box model

Source: Internet
Author: User

When you create a new HTML page with the editor, you will find a DOCTYPE tag on the top, for example:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" ><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" ><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" ><! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" ><! DOCTYPE html>

The above several DOCTYPE are standard document types, regardless of which mode is used to complete the definition of DOCTYPE, will trigger the Standard mode , and if doctype is missing will be triggered under the IE6,IE7,IE8 Weird mode (quirks mode).

First define a DIV block to demonstrate the difference between a standard pattern and a weird one, and here's the CSS style

. box {    width:200px;    height:200px;    border:20px solid black;    padding:50px;    margin:50px;}

Box model in Standard mode as shown, total width/height of box =width/height+padding+border+margin

Standard Mode box model

Box model in quirks mode as shown, the total width and height of the box are included in the width of the inner margin padding and border border, the total width/height of the box is =width/height + margin = content Area width/height + padding + border + margin;

Weird Mode box model

See here you should have a clear understanding of the two models of the box model, the following on the basis of the introduction of the CSS3 attribute box-sizing;

Box-sizing has two values one is Content-box and the other is Border-box.

When set to Box-sizing:content-box, will use the Standard mode analytic calculation, is also the default mode;

When set to Box-sizing:border-box, the odd mode is used to parse the calculation;

The current use of this property requires the following prefixes:

-webkit-box-sizing:content-box;-moz-box-sizing:content-box;

CSS box model full explanation, weird mode box model

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.