I'm Perfectly Centered!
Both horizontally and vertically
Flexbox is perfect for one-dimensional layouts. Here are the most common use cases!
Just add display: flex to the container!
.container {
display: flex;
}
flex-direction: row (default)
flex-direction: row-reverse
flex-direction: column
justify-content: flex-start
justify-content: flex-end
justify-content: center
justify-content: space-between
justify-content: space-around
justify-content: space-evenly
align-items: stretch (default)
align-items: flex-start
align-items: center
align-items: flex-end
flex-wrap: wrap - Items wrap to new line when needed
Control how items expand to fill space
The item with grow: 2 takes twice as much available space as grow: 1
.nav {
display: flex;
}
.spacer {
flex-grow: 1; /* Pushes Login to the right */
}
Card description goes here with some text.
More content for this card.
Even more card content here.
.card-container {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.card {
flex: 1 1 250px; /* grow, shrink, basis */
}
Both horizontally and vertically
.container {
display: flex;
justify-content: center; /* horizontal */
align-items: center; /* vertical */
min-height: 200px;
}