I am trying to create an ordered list of several columns, but I am struggling with CSS Grid layout rules.
The desired result should be responsive. On small screens, 2 grid columns, on large screens up to 4, while maintaining the order of the columns.
Instead of arranging as follows:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15
They should be ordered as follows:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12
I feel like I'm close with this violin .
ol {
margin: 0;
padding: 0;
list-style: none;
background-color: grey;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(33.333%, 50%));
grid-auto-flow: column;
grid-template-rows: repeat(5, 1em);
}
li {
outline: 1px solid orange;
}
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
<li>Item 10</li>
<li>Item 11</li>
<li>Item 12</li>
<li>Item 13</li>
<li>Item 14</li>
<li>Item 15</li>
</ol>
Run codeIn particular, I struggle with these points:
a) grid-auto-flow: columnrequires column processing to work, but also forces me to add grid-template-rows: repeat(5, 1em)to indicate the number of rows, which violates responsiveness. Is there a way to calculate the number of rows automatically based on the content and column?
b) ? , minmax ?