20 Essential CSS Flexbox Properties
A visual reference cheat sheet for mastering one-dimensional layouts in modern web design.
"Flexbox makes one-dimensional layouts simple, powerful, and flexible. Build better layouts with Flexbox!"
Container Properties (Flex Parent)
display: flex
Defines a flex container and enables a flex context for all its direct children.
.container {
display: flex;
}
flex-direction
Establishes the main axis, defining the direction flex items are placed in the container.
.container {
flex-direction: row;
}
flex-wrap
Specifies whether flex items are forced onto a single line or can wrap onto multiple lines.
.container {
flex-wrap: wrap;
}
flex-flow
A convenient shorthand property for setting both flex-direction and flex-wrap.
.container {
flex-flow: row wrap;
}
justify-content
Aligns flex items along the main axis (horizontally by default) and distributes extra space.
.container {
justify-content: center;
}
align-items
Defines the default behavior for how flex items are laid out along the cross axis (vertically).
.container {
align-items: center;
}
align-content
Aligns multiple lines within the flex container along the cross axis when extra space exists.
.container {
align-content: space-between;
}
gap
Explicitly controls the space between flex items, combining row-gap and column-gap.
.container {
gap: 20px;
}
row-gap
Sets the specific size of the gap (gutter) between flex container rows.
.container {
row-gap: 20px;
}
column-gap
Sets the specific size of the gap (gutter) between flex container columns.
.container {
column-gap: 20px;
}
Item Properties (Flex Children)
order
Controls the visual order in which flex items appear, independent of document source order.
.item {
order: 2;
}
flex-grow
Defines the ability for a flex item to grow relative to the rest of the items if space is available.
.item {
flex-grow: 1;
}
flex-shrink
Defines the ability for a flex item to shrink relative to the rest of the items when space is tight.
.item {
flex-shrink: 1;
}
flex-basis
Defines the default initial size of an element before remaining space is distributed.
.item {
flex-basis: 200px;
}
flex
Shorthand for flex-grow, flex-shrink, and flex-basis combined.
.item {
flex: 1 1 200px;
}
align-self
Allows the default alignment (from align-items) to be overridden for individual flex items.
.item {
align-self: flex-end;
}
Common Alignment Values
flex-start
Items are packed flush toward the start edge of the alignment container along the axis.
.container {
justify-content: flex-start;
}
flex-end
Items are packed flush toward the end edge of the alignment container along the axis.
.container {
justify-content: flex-end;
}
space-between
Items are evenly distributed; the first item touches the start edge and the last touches the end.
.container {
justify-content: space-between;
}
space-around
Items are distributed with equal space around them (spaces between items are double the edge spacing).
.container {
justify-content: space-around;
}

No comments:
Post a Comment