CSS3 Tutorial: Understanding the Box-sizing property border, padding and container width relationship

Source: Internet
Author: User

When it comes to IE's bug, a notorious example is its erroneous interpretation of the "box model": In the ie5.x and Quirks mode Ie6/7, border and padding are included within the width. This adds a lot of trouble to the work of the front-end engineer, and a couple of boxes that need to define the size have to think about it: "Box model Bug"?

At the same time, because of the standard compliance of another set of browsers, we also need to calculate the exact definition of a box that is displayed in a limited space: the space left to it is only that big, and the border and the padding, how much should we write its width?

This situation has improved in the CSS3 era, thanks to this property called Box-sizing, which has two values of "Content-box" and "Border-box".

Define Box-sizing:content-box; , the browser's interpretation of the box model conforms to the standards we have previously recognized;

Define Box-sizing:border-box; , the browser's interpretation of the box model is the same as IE6;

Why is this attribute "late"? IE's interpretation of the box model is not in line with the specification, but it also has its advantages: regardless of changes in the value of border and padding, will not cause the box total size changes, will not disrupt the overall layout of the page. And in modern browsers such as Firefox, if we want to change the value of padding, we have to recalculate box width. Now that IE6 is dead, this CSS property is a bit late.

Try this new property, Firefox Please use-moz-box-sizing,safari/webkit use-webkit-box-sizing,opera directly with box-sizing can.

CSS3 Tutorial: Understanding the Box-sizing property border, padding and container width relationship

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.