Hey there I am new to CSS grid. Have a look at the following example:
.platform {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
grid-gap: 20px;
}
.item {
width:100%;
background-color:#aaa;
padding:10px;
box-sizing:border-box;
text-align:center;
}
.wrapmed {
max-width:400px;
}
.wrapsmall {
max-width:300px;
}
<div class="platform">
<div class="item">a</div>
<div class="item">b</div>
<div class="item">c</div>
<div class="item">d</div>
</div>
<br/><br/>
<div class="wrapmed">
<div class="platform">
<div class="item">a</div>
<div class="item">b</div>
<div class="item">c</div>
<div class="item">d</div>
</div>
</div>
<br/><br/>
<div class="wrapsmall">
<div class="platform">
<div class="item">a</div>
<div class="item">b</div>
<div class="item">c</div>
<div class="item">d</div>
</div>
</div>
Basically the grid works great. However I never want to break the grid such that 3 items are on top and only one item is in the next row.
I want to have either 4 columns, or two colums, or one. (How) can I achieve this behavior?
Edit: The code snippet now shows the three possible cases. Case 2 is unwanted.
auto-fit
is doing exactly what you asked it to do. If you don't want this behaviour I'd suggest a re-think. – Graybeardauto-fit
/auto-fill
. But yes with media queries. jsfiddle.net/d0kroo27 – Spaniard