I want to do the following order with display:grid
1 9 17
2 10 18
3 11 19
4 12 20
5 13 21
6 14 22
7 15 23
8 16 24
So I want a total of 3 columns and to order items in rows first, then into the next column.
I want to do the following order with display:grid
1 9 17
2 10 18
3 11 19
4 12 20
5 13 21
6 14 22
7 15 23
8 16 24
So I want a total of 3 columns and to order items in rows first, then into the next column.
I decided to put in both ways, because while using column-count
, I could have in the order that you wanted the numbers.
And I used grid
there because it was the way you asked.
(Ignore the usage of flexbox, it was merely for styling purposes)
.examples {
display: flex;
gap: 100px;
}
.columns {
width: 100px;
column-count: 3;
}
.columns>label {
width: 20px;
height: 20px;
padding: 5px;
margin: 0px 5px 5px 0px;
border: 1px solid black;
display: flex;
justify-content: center;
align-items: center;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
width: 100px;
}
.grid > label {
width: 20px;
height: 20px;
padding: 5px;
margin: 0px 5px 5px 0px;
border: 1px solid black;
display: flex;
justify-content: center;
align-items: center;
}
<div class="examples">
<div class="columns">
<label>1</label>
<label>2</label>
<label>3</label>
<label>4</label>
<label>5</label>
<label>6</label>
<label>7</label>
<label>8</label>
<label>9</label>
<label>10</label>
<label>11</label>
<label>12</label>
<label>13</label>
<label>14</label>
<label>15</label>
<label>16</label>
<label>17</label>
<label>18</label>
<label>19</label>
<label>20</label>
<label>21</label>
</div>
<div class="grid">
<label>1</label>
<label>2</label>
<label>3</label>
<label>4</label>
<label>5</label>
<label>6</label>
<label>7</label>
<label>8</label>
<label>9</label>
<label>10</label>
<label>11</label>
<label>12</label>
<label>13</label>
<label>14</label>
<label>15</label>
<label>16</label>
<label>17</label>
<label>18</label>
<label>19</label>
<label>20</label>
<label>21</label>
</div>
</div>