So I have a grid for a section of a page as you can see below. Basically, the way its laid out is as follows:
[1] [ Item 1 ] [2] [ Item 2 ]
[3] [ Item 3 ] [4] [ Item 4 ]
And once the screen narrows to mobile via media queries it changes to this:
[1] [ Item 1 ]
[2] [ Item 2 ]
[3] [ Item 3 ]
[4] [ Item 4 ]
Which is perfect, that's what I need. My issue is that in the first example, I need it to go like this:
[1] [ Item 1 ] [3] [ Item 3 ]
[2] [ Item 2 ] [4] [ Item 4 ]
Now in my actual code, there are a lot more grid-items so basically I would like it to lay out the first column and then the second instead of filling row by row. I could physically change the order of the grid items in the HTML but then on mobile screens the order is messed up. I took a look at grid-auto-flow and I could not figure out if that's what I needed. The solution is probably so simple but I think I am so close to this project it's hard to take a step back and figure it out. Any help is greatly appreciated!
.grid {
display: grid;
grid-template-columns: 48px 1fr 48px 1fr;
column-gap: 12px;
align-items: center;
justify-content: center;
background-color: orange;
border: 1px solid black;
}
.grid-item {
padding: 16px;
border: 1px solid black;
font-size: 12px;
background-color: aliceblue;
}
<section class="grid">
<div class="grid-item">1</div>
<div class="grid-item">Item 1</div>
<div class="grid-item">2</div>
<div class="grid-item">Item 2</div>
<div class="grid-item">3</div>
<div class="grid-item">Item 3</div>
<div class="grid-item">4</div>
<div class="grid-item">Item 4</div>
</section>