Multiple Columns
The Newspaper Effect
Table of Contents
Multiple columns are great for organising content in newspaper style columns. They fit in wonderfully with fluid layouts because we can adjust the number of columns based on the width of the browser.
CSS3 Multiple Column Layout
Unfortunately, Microsoft have been very slow adopting multi-columns and it is not until IE10 that we see multiple column device support This means that older IE browsers will display the content as a single column, which we know can be hard to read across wide screens. What we need is a nice fall-back so that these IE browsers get an ideal reading width.
For more information, check out Multiple columns using CSS3.
Applying Multiple Columns
<!-- Markup -->
<section class="multicolumn">
...
</section>
Fall-back
No Multi-Column Support
To begin with, use the Modernizr JavaScript library which will feature test for multi-column support, by adding either csscolumns
or no-csscolumns
as a class attribute of the html
element. We can now apply a high CSS-specificity rule for non-supporting browsers to ensure they display content at an ideal reading width (about 33em).
No JavaScript
If no JavaScript is available, then Modernizr would not help us.
However, if we add a class-name to the root element, <html class="no-js">
,
then we can use it to detect if JavaScript is available. If not, the class-name no-js
will remain.
Otherwise, Modernizr will replace this class with js
.
Once again, we can apply a high CSS-specificity rule for non-JavaScript devices to achieve an ideal reading width.
This ideal reading width should not be used with widths less than 40em (640px), otherwise horizontal scrolling would be required. Columns must remain fluid (the default) up until this width. A media query will solve this for us.
Ideal reading width
@media screen and (min-width: 40em) {
.no-csscolumns .multicolumn, .no-csscolumns .widecolumns, .no-csscolumns .elastic-cols, .no-csscolumns .single,
.no-js .multicolumn, .no-js .widecolumns, .no-js .elastic-cols, .no-js .single {
width: 33em;
margin: 0 auto;
}
}
Increasing Column Count
Also, at the 40em (640px) point, we need to initialise the rule and gap for all widths,
beginning with two columns or .multicolumn
and one column for .widecolumns
.
/* CSS Set up for multiple columns */
@media screen and (min-width: 40em) {
.multicolumn, .widecolumns {
column-rule: 1px solid #c4c8cc;
column-gap: 40px;
column-count: 2; /* .multicolumn will have two columns */
}
.widecolumns {
column-count: 1; /* .widecolumns will still be one column at 40em (640px) */
}
}
The only need now is to increase the column count at varying widths, such as:
@media screen and (min-width: 60em) {
.multicolumn {
column-count: 3;
}
.widecolumns {
column-count: 2;
}
}
@media screen and (min-width: 80em) {
.multicolumn {
column-count: 4;
}
}
@media screen and (min-width: 100em) {
.multicolumn {
column-count: 5;
}
.widecolumns {
column-count: 3;
}
}
@media screen and (min-width: 120em) {
.multicolumn {
column-count: 6;
}
}
Device Testing
To appreciate the fluid layout, you will need to start testing with a supported browser.
Reduce the width of the browser as small as possible and you will have a fluid single column. The media queries will add more columns as the width increases. Most modern browsers let you zoom in and out using Ctrl+ and Ctrl- but Firefox and Opera also change the media query so that you will be able to see the column count changing across all widths. I recommend you try one of these browsers to see the effect.
Now using any IE browser < version 10 you will see an auto-centred single column set to an ideal reading width above 40em and the default fluid column below that width.
Another way to test the media queries for multiple columns is to use Firefox web developer ResizeView Responsive layouts.
Justified Alignment & Wide Columns
Notice in the above layout, the columns are wider and fully justified.
The CSS for the widecolumns
class was shown in the previous code snippets.
Here is the code for the justified
class, which can also be used on any block of content.
<!-- Markup -->
<section class="widecolumns justified">
...
</section>
/* Make Justified content more accessible */
.justified {
overflow: hidden;
text-align: justify;
}
Multi-Column List
All that is required is to wrap this ordered list in section class="multicolumn"
or section class="widecolumns"
block to preserve its natural order.
Once again, IE<10 will display the list as a single column, maintaining accessibility. Consider multiple column listing as a progressive enhancement (If the browser can do a better job of displaying content, then let it do it).
Gone are the days when we allow IE to stop progress on the web or to disallow the use of many new technologies that are with us today.
Native British Trees
-
Alders
- Alder (Alnus glutinosa)
-
Apples
- Crab Apple (Malus sylvestris)
-
Ashes
- Common Ash (Fraxinus excelsior)
-
Birches
- Silver Birch (Betula pendula)
- Downy Birch (Betula pubescens)
-
Beeches
- European Beech (Fagus sylvatica; southern Great Britain only)
-
Box
- Box (Buxus sempervirens; southern England only)
-
Cherries and Plums
- Wild Cherry (Prunus avium)
- Bird Cherry (Prunus padus)
- Blackthorn (Prunus spinosa)
-
Elms
- Wych Elm (Ulmus glabra)
- Smooth-leaved Elm (Ulmus minor, syn. U. carpinifolia; southern Great Britain only)
-
Hawthorns
- Common Hawthorn (Crataegus monogyna)
- Midland Hawthorn (Crataegus laevigata; southern Great Britain only)
-
Hazels
- Common Hazel (Corylus avellana)
-
Hornbeams
- European Hornbeam (Carpinus betulus; southern Great Britain only)
-
Hollies
- European Holly (Ilex aquifolium)
-
Junipers
- Common Juniper (Juniperus communis)
-
Lindens (Limes)
- Small-leaved Linden/Lime (Tilia cordata; southern Great Britain only)
- Large-leaved Linden/Lime (Tilia platyphyllos; southern Great Britain only)
-
Maples
- Field Maple (Acer campestre; southern Great Britain only)
-
Oaks
- Pedunculate Oak (Quercus robur)
-
Sessile Oak (Quercus petraea)
-
Pines
- Scots Pine (Pinus sylvestris)
-
Poplars
- Aspen (Populus tremula)
- Black Poplar (Populus nigra; southern Great Britain only)
-
Rowans and Whitebeams
- European Rowan (Sorbus aucuparia)
- Common Whitebeam (Sorbus aria) and several related apomictic microspecies
- Service Tree (Sorbus domestica; recently discovered growing wild on a cliff in south Wales)
- Wild Service Tree (Sorbus torminalis)
-
Strawberry Tree
- Strawberry Tree (Arbutus unedo; Ireland only)
-
Willows (Salix spp.; several species)
- Bay Willow (Salix pentandra)
- Crack Willow (Salix fragilis)
- White Willow (Salix alba)
- Almond-leaved Willow (Salix triandra)
-
Yews
- European Yew (Taxus baccata)
Elastic Columns
For this effect, we are using a container with a class of elastic-cols
,
which applies the rule of column-width: 14em;
.
As the width gets wider, the columns should remain consistent at 14ems. Each column will be very easy to visually scan.
The great thing about this technique is that there is no need to worry about media query boundaries. This rule can also be applied to the default mobile first style-sheet and automatically applied to any width.
The width will automatically accommodate additional columns to fit with as many 14em column widths and the 2em column gap as possible. Simplicity is often the best solution.
Additionally, a slightly wider elastic column width of 22em can also be used with a class of ideal-cols
Coding Elastic Columns
<!-- 14em Elastic Columns -->
<section class="elastic-cols">
...
</section>
<!-- 22em Elastic Columns -->
<p class="ideal-cols">
...
</p>
/* CSS */
.elastic-cols, .ideal-cols {
column-width: 14em;
column-gap: 2em;
column-rule: thin dotted #ccc;
}
.ideal-cols {
column-width: 22em;
}
Read more about fluid and responsive Layouts.