Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /css/css-grid/grid-definition/grid-auto-fit-collapsed-gutters-001.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="match" href="grid-auto-fit-collapsed-gutters-001-ref.html">
<meta name="assert" content="Empty auto-fit tracks are collapsed to 0px and the gutters on either side of a collapsed track coincide, so the items are separated by a single gap.">
<style>
.grid {
display: grid;
width: 300px;
margin-bottom: 10px;
background: lightgray;
column-gap: 10px;
grid-template-columns: repeat(auto-fit, 50px);
}
.item {
height: 50px;
background: green;
}
</style>
<!-- 5 tracks. Tracks 1, 2 (leading) and 4 (middle) are empty and collapse. -->
<div class="grid">
<div class="item" style="grid-column: 3"></div>
<div class="item" style="grid-column: 5"></div>
</div>
<!-- Same, with a larger gap. 4 tracks fit in 300px. Tracks 1 and 3 hold the items; tracks 2 and 4 are empty. -->
<div class="grid" style="column-gap: 30px">
<div class="item" style="grid-column: 1"></div>
<div class="item" style="grid-column: 3"></div>
</div>