The CSS Flexible Box Layout Module (Flexbox) is a one-dimensional layout model that offers an efficient way to lay out, align, and distribute space among items in a container, even when their size is unknown or dynamic.
Flexbox makes it simple to solve common layout problems that were historically difficult with CSS. It's perfect for:
Click an item in the visualizer to select it and edit its properties.
/* Container Styles */
.container
{
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
flex-wrap: nowrap;
align-content: stretch;
gap: 10px;
}
Use the playground controls to achieve the following layouts. Click "Show Solution" to see the CSS.
Make all items stack vertically in a column, centered on the page (both horizontally and vertically).
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
Arrange 3 items so they are in a row, with the middle item taking up all the extra space.
/* Set container to: */
flex-direction: row;
/* Select Item 2 and set: */
.item-2 {
flex-grow: 1;
}
Make the items appear in the order 3, 1, 2.
/* Select Item 1: */
.item-1 { order: 2; }
/* Select Item 2: */
.item-2 { order: 3; }
/* Select Item 3: */
.item-3 { order: 1; }