I have 2 layouts I want to use for a CSS grid depending on if there is enough width to display the items without them being too squeezed.
Each coloured block should take the space it needs to display its content without wrapping.
If the display is too narrow then each of the coloured blocks would stack veritcally and take the full width.
I've tried a number of solutions but can't figure this out.
Can anyone help me achieve this please? Thanks!
NB. please ignore the stretched text the pics are just for layout
.container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
text-align: center;
}
.grid>div:first-child {
grid-column: span 8;
}
.firstItem {
background: yellow;
}
.option {
height: 100%;
min-height: 90px;
}
.secondItem {
display: grid;
grid-auto-flow: column;
}
.optionsContainer {
background-color: grey;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.check {
background-color: pink;
}
<div class='container'>
<div class='firstItem'>
I am the first item</div>
<div class='secondItem'>
<div class='optionsContainer'>
<div class='option'>
option 1
</div>
<div class='option'>
option 2
</div>
<div class='option'>
option 3
</div>
</div>
<div class='check'>
<input type='checkbox' />
<label>I am the checkbox</label>
</div>
</div>
</div>