https://i.sstatic.net/u759j.png
.multiCol {
display: table;
table-layout: fixed; // maintains consistent width
width: 100%;
text-align: left; // personal preference for alignment
.col {
display: table-cell;
vertical-align: top;
width: 50%;
padding: 2% 0 2% 3%; // spacing between columns
&:first-of-type { padding-left: 0; } // no padding on the first column
}
}
Add this code to your custom theme right before
// Theme template ------------------------------
@import "../template/theme";
// ---------------------------------------------
How to use? - simple! Can be used with any number of columns:
<section>
<h3>Creating two-column layouts (> full-width heading)</h3>
<div class='multiCol'>
<div class='col'>
Gallia est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur.
</div>
<div class='col'>
Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.
</div>
</div>
Additional full-width text follows. You can also create:
<div class='multiCol'>
<div class='col'>Works for 3 columns too...</div>
<div class='col'>...as demonstrated in...</div>
<div class='col'>...this example.</div>
</div>
</section>
- No need for floats
- No need for clearfix hacks
- Responsive design (using percentages only)
- Suitable for 2, 3, 4 columns and more...
<table>
is often considered outdated due to historical misuse in layout, but as a property layout:table
, it has valid uses, offers simplicity, and is widely supported.