CSS Flexbox Layout Guide CSS-Tricks
CSS Flexbox Layout Guide CSS-Tricks
HOME / GUIDES /
Part 5: Examples
DOWNLOAD FREE
Part 6: Flexbox tricks
Part 7: Browser support
Part 8: Bugs
Part 9: Related properties
Part 10: More information
Part 11: More sources
Background
Flexbox properties
display order
This defines a flex container; inline or
block depending on the given value. It
enables a flex context for all its direct
children.
CSS
.container {
display: flex; /* or inline-flex */
}
CSS
.item {
order: 5; /* default is 0 */
}
CSS
.container {
flex-direction: row | row-reverse | column | column-reverse;
}
CSS
.item {
flex-grow: 4; /* default 0 */
}
CSS
.container {
flex-wrap: nowrap | wrap | wrap-reverse;
flex-shrink
} This defines the ability for a flex item to
shrink if necessary.
nowrap (default): all flex items will be
CSS
CSS
content” – this keyword isn’t well
.container { supported yet, so it’s hard to test and
flex-flow: column wrap; harder to know what its brethren max-
} content, min-content, and fit-content
do.
CSS
.item {
justify-content flex-basis: | auto; /* default auto */
}
flex
This is the shorthand for flex-grow,
flex-shrink and flex-basis combined.
The second and third parameters (flex-
shrink and flex-basis) are optional.
The default is 0 1 auto, but if you set it
with a single number value, like flex: 5;,
that changes the flex-basis to 0%, so it’s
like setting flex-grow: 5; flex-
shrink: 1; flex-basis: 0%;.
CSS
.container {
justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly
}
align-self
flex-start (default): items are packed
toward the start of the flex-direction.
flex-end: items are packed toward the
end of the flex-direction.
start: items are packed toward the
start of the writing-mode direction.
end: items are packed toward the end of
the writing-mode direction.
This allows the default alignment (or the
left: items are packed toward left edge
of the container, unless that doesn’t one specified by align-items) to be
make sense with the flex-direction, overridden for individual flex items.
then it behaves like start.
Please see the align-items explanation to
right: items are packed toward right
understand the available values.
edge of the container, unless that
doesn’t make sense with the flex- CSS
align-items
CSS
.container {
align-items: stretch | flex-start | flex-end | center | baseline | first baseline | last basel
}
align-content
CSS
.container {
align-content: flex-start | flex-end | center | space-between | space-around | space-evenly |
}
CSS
.container {
display: flex;
...
gap: 10px;
gap: 10px 20px; /* row-gap column gap */
row-gap: 10px;
column-gap: 20px;
}
Prefixing Flexbox
Examples
Flexbox tricks!
Browser support
Bugs
Related properties
More information
More sources
Psst! Create a DigitalOcean account and get $200 in free credit for cloud-based hosting and
services.
Comments
Leave a Reply
Name
Website
Save my name, email, and website in this browser for the next time I comment.
POST COMMENT
DigitalOcean.