Utilizing CSS3 properties like flexbox
, you can achieve the following layout:
ul {
flex-direction: column;
flex-wrap: wrap;
display: flex;
height: 100vh;
}
ul li {
flex: 1 0 25%;
}
The above CSS will generate a grid layout as shown below:
+--------------------+
| 01 | 05 | 09 |
+--------------------+
+--------------------+
| 02 | 06 | 10 |
+--------------------+
+--------------------+
| 03 | 07 | 11 |
+--------------------+
+--------------------+
| 04 | 08 | 12 |
+--------------------+
If you desire a different layout like the one demonstrated below:
+-----------------------+
| 1 | 2 | 3 | 4 |
+-----------------------+
+-----------------------+
| 5 | 6 | 7 | 8 |
+-----------------------+
+-----------------------+
| 9 | 10 | 11 | 12 |
+-----------------------+
You can implement the following CSS styles:
ul {
flex-wrap: wrap;
display: flex;
}
ul li {
flex: 1 0 25%;
}
* {box-sizing: border-box;}
body {
margin: 0;
}
.list {
list-style: none;
flex-wrap: wrap;
display: flex;
padding: 0;
margin: 0;
}
.list li {
border-bottom: 1px solid #fff;
flex: 1 0 25%;
padding: 10px;
color: #fff;
}
.list li:nth-child(4n + 1) {
background: blue;
}
.list li:nth-child(4n + 2) {
background: orange;
}
.list li:nth-child(4n + 3) {
background: green;
}
.list li:nth-child(4n + 4) {
background: purple;
}
<ul class="list">
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
<li>Test 5</li>
<li>Test 6</li>
<li>Test 7</li>
<li>Test 8</li>
<li>Test 9</li>
<li>Test 10</li>
<li>Test 11</li>
<li>Test 12</li>
</ul>