<image source: codecademy.com>
margin = 0
, the edge of the element will be touching the edge of the adjacent elementmargin: 0 auto
is used to horizontally center the element (the element's width
must be defined first for this to work)With the default box model, when you set the width and height of an element, the actual(total) width/height will be different from the width/height you have specified - because of padding & border.
The default box model, as above, is
box-sizing: content-box
> here the width/height you specify for the element will be the width/height of the element's content
In order to have a total element width/height that doesn't change with padding & border specifications, you must change the default box model. This would be
box-sizing: border-box
> here the width/height you specify for the element will be the width/height of the entire element (content + padding + border). The width/height of the content will be auto adjusted
> To make this box model apply to the entire CSS document, you can use the * selector at the beginning of the document:* { box-sizing: border-box; }