I'm trying to display a variable number of divs across two lines, like this:
[1] [3] [5] [7]
[2] [4] [6] ...
I've explored using the column-count
property in CSS, but it doesn't quite fit my needs since it requires a fixed number of columns. I wish there was something like a line-count property available.
Is there a way to achieve this with pure CSS, or should I create container divs for every group of two vertical divs?
Thanks!
Edit:
I have simplified the code example to showcase my issue. Even though I have set the height
property for the container div, shouldn't the article divs stack by twos? Currently, they are overflowing the container.
<html>
<head>
<link rel="stylesheet" type="text/css" href="test.css">
</head>
<body>
<div class="container">
<div class="article">A</div>
<div class="article">B</div>
<div class="article">C</div>
<div class="article">D</div>
<div class="article">E</div>
</div>
</body>
</html>
Here is the corresponding CSS:
.article {
width:50px;
height:50px;
border:1px gray dashed;
margin:1px;
}
.container {
height:110px;
max-height:110px;
}
Despite the code configuration, all the article divs are displaying in a single column.