Home>Article>Web Front-end> A closer look at the css3 border-sizing property
Recommended:css video tutorial
box-sizing
For changing the default used to calculate the width and height of elements CSS box model. It has three values:content-box
,border-box
andinherit
.inherit
refers to inheriting thebox-sizing
expression form from the parent element, which is no longer redundant.
content-box
The default value is also the box model in CSS2.1. When calculatingwidth
andheight
,border
,padding
andmargin
are not calculated.Height and width are just the content height.
border-box
css3
Newly added. Thewidth
andheight
properties include content, padding, and borders, but not margins.
Calculation formula:
border-boxmargin
is not calculated, but
borderand
paddingare calculated redundantly.
Becauseborderand
paddingare both part of the box model, but
marginmarks the distance between boxes
. Therefore, the explanation ofborder-boxis very common sense.
The question is, ifAchieve the following renderings:margin
must be set sometimes,
how to achieve free control to ensure compatibility? For example, we want to set up a box element that fills the entire page and is interfered with by margins. How should we do this?
yuanxin.me
So, when you need to calculate the margin, you can usewith the four arithmetic operations (calc
) in css3.
Based on the usage experience in the project and the recommendations of w3c, it is recommended to set theFor more programming-related knowledge, please visit:box-sizing
attribute to
border-box.
* { margin: 0; padding: 0; } div { box-sizing: border-box; }
Introduction to Programming! !
The above is the detailed content of A closer look at the css3 border-sizing property. For more information, please follow other related articles on the PHP Chinese website!