Box-sizing properties of boxes in CSS3

Source: Internet
Author: User

Box-sizing

Properties

box-sizing property is used to change the way the default CSS box model calculates the width of the element. This property can be used to simulate the performance of browsers that do not correctly support the standard box model.

box-sizing:content-box (default) | Border-box;

content-box

Default value, standard box model. Width and height include only the width and height of the content, excluding the border (border), padding (padding), margin (margin).

Note: The padding, borders & margins are outside the box.

Like what. If. box {width:350px}; and {border:10px solid black;} then the actual width of the rendering in the browser will be 370px;

    
   Dimension Calculation formula:width = content, height = content. Both width and height do not contain the content's border (border) and padding (padding).

Border-box  

Width and height include padding (padding) and border (border), excluding margin (margin).

This is the box model used by IE quirks mode (Quirks modes). Note: The padding and borders will be included in the box at this time.

like .box {width: 350px; border: 10px solid black;} 浏览器渲染出的宽度将是350px .

If the calculated internal content is negative, it will be calculated as 0 and the content is still there, so it is not possible to hide the element through Border-box.

      
    Dimension Calculation formula:width = border + padding + content widths, height = border + padding + content height.

Demo

<! DOCTYPE html>{/*the value of padding border is included when calculating Height,width*/-webkit-box-sizing:Border-box;-moz-box-sizing:Border-box;box-sizing:Border-box;/*padding is not included when calculating height,width border*/            /*-webkit-box-sizing:content-box;*/            /*-moz-box-sizing:content-box;*/            /*Box-sizing:content-box;*/            /*the value of padding is included when calculating Height,width *!/*/            /*-webkit-box-sizing:padding-box;*/            /*-moz-box-sizing:padding-box;*/            /*Box-sizing:padding-box;*/Background-color:Gray;Border:10px Orange Solid;width:500px;Height:300px; }</style>

Link ...

Https://developer.mozilla.org/zh-CN/docs/Web/CSS/box-sizing

Box-sizing properties for boxes in CSS3

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.