in the css-tricks complete-guide-to-css-grid it describes the justify-content property as follows:
justify-content Sometimes the total size of your grid might be less than the size of its grid container. This could happen if all of your grid items are sized with non-flexible units like px. In this case you can set the alignment of the grid within the grid container. This property aligns the grid along the inline (row) axis (as opposed to align-content which aligns the grid along the block (column) axis).
Im trying to wrap my head around how this works. If I have a grid container with width: 100% and grid items with fixed width width: 20px and I set the grid container to justify-items: start the grid items will, as expected justify to the start. If however, I set the grid container to `grid-template-columns: repeat(4, 1fr) then the items no longer justify to the start? even though the items are sized with non-flexible units?
According to the css-tricks description I would have expected them to justify to the start of the row axis?
.wrapper{
width: 100%;
height: 100vh;
}
.grid{
display: grid;
grid-auto-flow: column;
justify-content: start;
align-content: start;
width: 100%;
padding: 1em;
background-color: powderblue;
}
.grid.explicit{
grid-template-columns: 1fr 1fr 1fr 1fr;
}
.grid__item{
width: 20px;
padding:0.6em;
background-color: lime;
}
<div class="wrapper">
Explicit columns
<pre>
grid-template-columns: 1fr 1fr 1fr 1fr;
</pre>
<div class="grid explicit">
<div class="grid__item">item</div>
<div class="grid__item">item</div>
<div class="grid__item">item</div>
<div class="grid__item">item</div>
</div>
Implicit columns
<div class="grid">
<div class="grid__item">item</div>
<div class="grid__item">item</div>
<div class="grid__item">item</div>
<div class="grid__item">item</div>
</div>
1fr. Since you have set a specific width (albeit infrunits) the grid-columns are what you have set and then the grid-items are aligned as directed within those cells. - Paulie_D