Css3: box Model and box-sizing attributes, css3box-sizing

Source: Internet
Author: User

Css3: box Model and box-sizing attributes, css3box-sizing

Each element in the document is depicted as a rectangular box. The purpose of the rendering engine is to determine the size and attributes, such as the color, background, and border of the rendering engine, and the location of these boxes. In CSS, these rectangular boxes are described using the standard box model. This modelSpace occupied by an element. Each box has four borders: the outer margin boundary margin, the border Boundary border, the inner margin boundary padding, And the content boundary.

 

  • In W3C model: total width = margin-left + border-left + padding-left + width + padding-right + border-right + margin-right

  • In the IE model: total width = margin-left + width + margin-right

Introduced in CSS3Box-sizingAttribute, which allows you to change the calculation method of the default CSS Box Model for element width.

There are two options:

  • Content-box: Standard box model. The width and height defined by CSS only contain the width and height of content. (Default)

  • Border-box: IE box model. The width and height defined by CSS include content, padding, and border.

 

Instance:

(Con1 is set to box-sizing: border-box, and con is the default content-box)

 1 

 

The differences between the two boxes can be clearly seen on the console.

The box model of the first div is as follows: content-box

 

The box model of the second div is as follows: border-box

 

 

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.