css · level 2 · unit 1 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
shares the between the children.
Put a search box and a button in a wide flex row and there is empty room at the end. That leftover room is the free space.
flex-grow hands it out. It is a plain number, and the default is 0, so nobody grows. Give every child flex-grow: 1 and they share the free space equally.
Give one child flex-grow: 2 and it gets two shares for every one the others get. Give it to the search box alone and it takes the whole lot.
<div class="bar">
<input class="search" placeholder="Search recipes">
<button>Go</button>
</div> .bar {
display: flex;
gap: 8px;
}
.search {
flex-grow: 1;
} Press show my page to see it here.
<input> is a box people type into. It grows to fill the row while the button keeps its size.
guess first
Only the middle tile has flex-grow. What do you see?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<div class="row">
<div class="tile">A</div>
<div class="tile wide">B</div>
<div class="tile">C</div>
</div> .row {
display: flex;
}
.tile {
padding: 12px;
background-color: khaki;
}
.wide {
flex-grow: 1;
}
your turn
Your turn. Share the row between the tabs.
Make every tab grow, so the three tabs fill the whole row between them.
the page you’re styling
<div class="tabs">
<a class="tab" href="https://example.com/day">Day</a>
<a class="tab" href="https://example.com/week">Week</a>
<a class="tab" href="https://example.com/month">Month</a>
</div>your css
Press show my page to see it here.
- the tabs grow to fill the rownot checked yet
fix it
The search box will not grow. Fix it!
the page you’re styling
<div class="bar">
<input class="search" placeholder="Search books">
<button>Find</button>
</div>your css
Press show my page to see it here.
- the search box takes the free spacenot checked yet
- The browser skipped one declaration. Which value looks odd?
flex-growcounts shares, so it is a plain number with no unit.- Change
1pxto1, then press run.
nailed it
you shared out the spare room. :D
- Free space is the room left over in a flex row.
flex-growhands out shares of it;0means no share.flex-growis a plain number with no unit.
new words in your collection
- free space
- flex-grow
This lesson isn’t saved. A free account remembers every lesson you finish.