I have a multi-column div with paragraphs, and I need the last paragraph in any cluster of paragraphs to end with a space at the bottom. Currently, I achieve this with a margin-bottom
on p
and then an equal negative margin-top
on p+p
. This all works fine. Then, I add a column-spanning div below those paragraphs. For some reason, the spanner seems to ignore the margin-bottom
of the paragraphs in column one, which means if the columns are unbalanced, my div ignores the spacing (and in fact is painted on top of the margin if you view it in the Chrome inspector), bunching up close to the paragraph above. Is there some clean solution to get consistent spacing? You can see this happening in the snippet here:
.container {
column-count: 2;
border: solid black 1px;
width: 200px;
}
.spanner {
background-color: #aaf;
column-span : all;
}
p {
margin-top : 0px;
margin-bottom: 20px;
padding : 5px;
background-color : #ffa;
}
p+p {
margin-top: -20px;
}
<b>Balanced columns are fine:<b>
<div class="container">
<p>1 1 1 1 1 1 1 1 1 1 1</p>
<p>2 2 2 2 2 2 2 2 2 2 2</p>
<p>3 3 3 3 3 3 3 3 3 3 3</p>
<p>4 4 4 4 4 4 4 4 4 4 4</p>
<p>5 5 5 5 5 5 5 5 5 5 5</p>
<p>6 6 6 6 6 6 6 6 6 6 6</p>
<div class="spanner"> span the whole column, bro. </div>
</div>
<br>
<br>
<b>Unbalanced columns ruin my life:<b>
<div class="container">
<p>1 1 1 1 1 1 1 1 1 1 1</p>
<p>2 2 2 2 2 2 2 2 2 2 2</p>
<p>3 3 3 3 3 3 3 3 3 3 3</p>
<p>4 4 4 4 4 4 4 4 4 4 4</p>
<p>5 5 5 5 5 5 5 5 5 5 5</p>
<div class="spanner"> span the whole column, bro. </div>
</div>
Edit: Added additional context, because the proposed answers didn't quite solve the issue in my case.