I have a code like this:
<div class="article-container">
<div class="article">
<h3>title1</h3>
<p>article1</p>
</div>
<div class="article">
<h3>title2</h3>
<p>article2</p>
</div>
<div class="article">
<h3>title3</h3>
<p>article3</p>
</div>
<div class="article">
<h3>title4</h3>
<p>article4</p>
</div>
</div>
and I want to transform this 1 lined column into 2 columns like this:
I already tried to use this code, but is there any different way to split the div?
.article-container {
display: flex;
flex-wrap: wrap;
}
.article {
flex-grow: 1;
flex-basis: 50%;
}
.article:after {
content: "";
flex: auto;
}
<div class="article-container">
<div class="article">
<h3>title1</h3>
<p>article1</p>
</div>
<div class="article">
<h3>title2</h3>
<p>article2</p>
</div>
<div class="article">
<h3>title3</h3>
<p>article3</p>
</div>
<div class="article">
<h3>title4</h3>
<p>article4</p>
</div>
</div>
It's different from this other question Split Div Into 2 Columns Using CSS, the "article" arrangement from this question is different. Anyone got the idea?
This is actually quite simple. You just need to set
.article
todisplay: inline-block;
, and seporate the second one from the first one with a<br>
, and perhapswidth: 49%;
on the.article
to get the effect of a proper columnYou may try using CSS3 Columns. But in this case, it looks a bit different in the information flow.
Nothing wrong with flexbox for this layout.
There's no need to use a pseudo-element.
Here's one way using float/clear: