Understanding the CSS Box Model and how it affects layout and spacing
The CSS Box Model
width
and height
properties.
width
and height
properties in CSS only set the size of the content area. This means that padding and border are added to the specified width and height, which can make layout calculations difficult.
The box-sizing
property changes how the width and height of elements are calculated:
box-sizing: border-box
for all elements to make layout calculations more intuitive. This can be applied globally with:Margin Collapse Example
overflow: hidden
)Box Model in Chrome DevTools
box-sizing
property determines how width and height are calculated