Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<meta charset="utf-8">
<link rel="match" href="grid-auto-fit-fewer-items-than-tracks-001-ref.html">
<meta name="assert" content="With fewer items than repetitions the empty tracks collapse and the flexible tracks which remain share the whole container, separated only by the gutters between them.">
<style>
.grid {
display: grid;
width: 380px;
margin-bottom: 10px;
background: lightgray;
column-gap: 10px;
grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
}
.item {
height: 50px;
background: green;
}
</style>
<!-- 6 tracks fit. 3 items leave 3 tracks empty. -->
<div class="grid">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<!-- 2 items leave 4 tracks empty. -->
<div class="grid">
<div class="item"></div>
<div class="item"></div>
</div>