What does * { box-sizing: border-box; } do? What are its advantages?
-
Make every element in the document include the padding and border in the element’s inner dimensions;
making it easier to reason about the layout of elements on the page. -
By default, elements have
box-sizing: content-box
applied, and only the content size is being accounted for. -
box-sizing: border-box
changes how thewidth
andheight
of elements are being calculated,border
andpadding
are also being included in the calculation. -
The
height
of an element is now calculated by the content’sheight
+ verticalpadding
+ verticalborder
width. -
The
width
of an element is now calculated by the content’swidth
+ horizontalpadding
+ horizontalborder
width. -
Taking into account
padding
s andborder
s as part of our box model resonates better with how designers actually imagine content in grids.