I have a form that looks like this:
I have laid it out using CSS grid:
<div style="display: inline-grid; grid-template-columns: auto auto auto auto">
<div><input></div>
<div><input></div>
<div><input></div>
<div style="font-family: sans-serif; font-weight: bold; font-size: 20px; line-height: 20px;">⊖</div>
<div><input></div>
<div><input></div>
<div><input></div>
<div style="font-family: sans-serif; font-weight: bold; font-size: 20px; line-height: 20px;">⊖</div>
<div><input></div>
<div><input></div>
<div><input></div>
<div style="font-family: sans-serif; font-weight: bold; font-size: 20px; line-height: 20px;">⊖</div>
</div>
On small screens I would like the layout to change to this:
But I don’t know how to change the CSS grid to get this layout, if that’s even possible.
2
Answers
Simply make those
<div>
s with<input>
span 3 columns, those without span 3 rows and ensure that the grid is as dense as possible:Try it:
Here’s some
:nth-child()
logic that may be helpful.(re-size the screen to switch between layouts)