heightwidthblock — 100%inline / inline-block — content widthwidth & height propertiesmin- and max- versionsmarginborderpaddingmarginmargin pushes elements away from other elements
Neighboring margins collapse.
E.g., margin-bottom: 10px followed by margin-top: 20px creates a 20px gap.
margin.margin is pushing me in from my parent's edges.paddingpadding pushes an element's contents away from its edges
Note: there's a caveat with padding coming later…
padding.padding is pushing my contents away from my edges.borderborder adds to an element's height and width (like margin); it doesn't force its contents in (like padding).
border adds 20px to my width & height.border adds 10px to my width & height.Element Contents
box-sizingcontent-box: padding can affect element size (browser default, ugh)
border-box: padding doesn't affect element size (every reset/normalize CSS)
.box {
padding: 20px;
height: 140px;
width: 500px;
}
box-sizing: content-box 540px widebox-sizing: border-box 500px widedisplayIf an element is inline, its padding won't force it off the baseline, and it won't respond to vertical margin.
If an element is inline-block (or block), its padding will affect its baseline, and it will respond to vertical margin.
em {
padding: 10px;
margin: 10px 40px;
background-color: rgba(0,0,0,.5);
}
floatfloat makes an element's width exactly what its contents need, even if it's a block element.
All other elements (that aren't explicitly cleared) flow around a floated element.
display: table
display: flex
display: grid
display: tableChildren behave like display: table-row…
… unless they're set to be display: table-cell.
display: block (default)display: block (default)display: table-celldisplay: table-celldisplay: flexChildren are sized according to flexbox rules applied to parent…
… and flexbox rules applied to children.
display:blockdisplay:blockdisplay:blockdisplay:block; align-self: flex-enddisplay: gridChildren are sized according to grid rules applied to parent…
… and grid rules applied to children.
That's another talk though…
marginborderpaddingElement Contents
box-sizingdisplayfloatjdsteinbach