What does * { box-sizing: border-box; } do? What are its advantages?
Quiz · CSS
Medium
3 min
css
- By default, elements have
box-sizing: content-boxapplied, and only the content size is being accounted for. box-sizing: border-boxchanges how thewidthandheightof elements are being calculated,borderandpaddingare also being included in the calculation.- The
heightof an element is now calculated by the content'sheight+ verticalpadding+ verticalborderwidth. - The
widthof an element is now calculated by the content'swidth+ horizontalpadding+ horizontalborderwidth. - Taking into account
paddings andborders as part of our box model resonates better with how designers actually imagine content in grids.
Adapted from the Front End Interview Handbook by Yangshun Tay and contributors (MIT License). Source
Spotted a mistake or a rights concern? Report an issue