CSS takes a source document organized as a tree of elements… and text nodes… and renders it onto a canvas such as your screen.
The document canvas is the infinite surface over which the document is rendered.
width
/height
to start fromdisplay
property
Box Generation Values
display
propertyDisplay:none;
(head/style) removes box & subtreeDisplay:contents;
(figure?) removes boxDisplay:list-item;
(li) generates a second ::marker
boxList-style-position
moves ::marker
in or out of primary boxdisplay: none
Removes Box Tree
display: contents
Removes Box (Only)
div
s when doing layoutdisplay: list-item
Adds Marker Box
list-item
keyword::marker
boxdisplay
context…
Flow, Flex, Grid, Table-*…
Set on the container for a layout
display
values are set on a container elementdisplay
behavior
Inline or Block
Set on the elements of a (flow) layout
inline
or block
)demo:
width
to editableheight
display: block
display
of the element itself…body { display: flex; }
flow
is the default…display: block
display: block
flow
;
inline
» inline
flow
block
or inline
display: block flow
in modern browsers.display
…
Flow or Flow-Root
flow
or flow-root
display: flow
display:
block
flow;
flex
» block
flex
flow
or flex
or grid
block
grid
is the same as display: block grid
display
actually doeswriting mode
[demo link]inline-size
is the heightblock-size
is the widthdirection
[demo link]top
, right
, bottom
, and left
(fixed in place)block-start
, block-end
, inline-start
, inline-end
(in English, for example…)
width
-> inline-size
height
-> block-size
top
-> block-start
bottom
-> block-end
left
-> inline-start
right
-> inline-end
margin-right
with margin-inline-end
block
and inline
shorthands for somemargin-block
, padding-inline
, border-block
, etcinput {
margin-inline-end: 1em;
margin-right: 0;
}
0px
if they are the same sidemargin-inline-end
here0
, the margin-right valueinline
and block
go all the way back to the startem
size.flex > span {
inline-size: 50%;
}
%
and other ‘relative’ units)min-content
|max-content
| fit-content
“A mini layout in your layout”…
overflow: hidden;
to trigger a…hasLayout
in IE)display: flow-root
display:
block
flow-root;
grid
» block
grid
flow-root
or grid
)block
inline-flex
, inline-grid
, inline-block
inline-flex
➡️ inline flex
inline-grid
➡️ inline grid
inline-block
➡️ inline flow-root
inline-block
nowinline flow-root
distributing extra space
Block axis comes first
Which axis are we manipulating?
justify-*
props apply to the ‘inline’ axisalign-*
props apply to the ‘block’ axisstretch
start
| center
| end
self-*
| flex-*
safe
‘clamps’ alignment at the start-direction
and -wrap
(or -flow
)gap
on containeralign-items
on the flexbox containerplace-
or align-
justify-
in relation toplace-content
space-between
| -around
| -evenly
place-
self
to
Move Individual Items
Explicit on each element
place-
items
to
Move All Items
A default from the container
place-
content
to
Move Entire Layout
space
-between
| -around
| -evenly
align-content
align-
self
…
From Container Align-Items
(each item can still align-self
to override)
.defaults {
flex-basis: auto; /* starting width */
flex-shrink: 1; /* distribution factor */
flex-grow: 0; /* distribution factor */
}
auto
content sizeflex
Shorthand Values
initial
| auto
| none
| <grow>
Initial
Shrink, If Necessary
Same as 0 1 auto
Auto
Shrink or Grow
Same as 1 1 auto
None
Don’t Flex
Same as 0 0 auto
<number>
Share Space Equally
Same as <number> 1 0
<grow>
Not a strict rule, just a hint!