Flexbox is a CSS layout model that allows items inside a container to be arranged in flexible, responsive ways.
display: flexThis property turns an element into a flex container, making its children flex items.
.container {
display: flex;
}
flex-directionThis property defines the direction of the flex items inside the container. It can be row (default), row-reverse, column, or column-reverse.
.container {
display: flex;
flex-direction: row; /* Items placed in a row */
}
justify-contentThis property aligns flex items along the main axis (horizontal by default). Values include: flex-start, flex-end, center, space-between, space-around, space-evenly.
.container {
display: flex;
justify-content: center; /* Centers items along the horizontal axis */
}
align-itemsThis property aligns flex items along the cross axis (vertical by default). It can take values like flex-start, flex-end, center, stretch, and baseline.
.container {
display: flex;
align-items: center; /* Centers items vertically */
}
flex-wrapThis property controls whether flex items should wrap onto multiple lines if needed. Values: nowrap, wrap, wrap-reverse.
.container {
display: flex;
flex-wrap: wrap; /* Items will wrap when necessary */
}
flex-growThis property defines how much a flex item should grow relative to the other items. A value of 0 means it won’t grow.
.item {
flex-grow: 1; /* Item will grow to fill available space */
}
flex-shrinkThis property defines how much a flex item should shrink if the container becomes smaller. A value of 0 means it won’t shrink.
.item {
flex-shrink: 0; /* Item will not shrink */
}
Flexbox is a powerful layout system in CSS that allows you to align and distribute space between items in a container with ease. By using various flex properties, you can create responsive layouts with minimal effort.