Laying things out in a row
Use flexbox to put elements side by side and space them.
Your CSS is drawn by your own browser, inside this tab. Nothing to install.
From a column to a row
Normally boxes stack down the page, one under the other.
display: flex on an element lays its children out in a row instead. The element you put it on is called the container.
Here the container is the menu list, and its children are the three list items. list-style: none removes the bullets.
#menu {
display: flex;
list-style: none;
}Your turn: a row
Put flex on the container, not on the items.
Practice task
Lay the three menu items out in a row by making #menu a flex container.
Your answer is run and checked in the lesson. Create a free account to try it.
Space between the items
gap puts space between the children of a flex container. It adds none at the two ends.
This is simpler than giving every item a margin.
#menu {
display: flex;
list-style: none;
gap: 24px;
}Spreading items out
justify-content says where the children go along the row.
center gathers them in the middle. space-between pushes the first and last to the edges and shares the space left over. flex-end moves them to the far side.
#menu {
display: flex;
list-style: none;
justify-content: space-between;
}Your turn: a centred row
Combine what this topic covered.
Practice task
Make #menu a flex container, centre its items along the row, and put a gap of 16 pixels between them.
Your answer is run and checked in the lesson. Create a free account to try it.