Code Snippet
Multiple Columns
Here is an example of a simple three-column class:
.three-col {
-moz-column-count: 3;
-moz-column-gap: 20px;
-webkit-column-count: 3;
-webkit-column-gap: 20px;
}Of which you would apply to a block of text like so:
<p class="three-col">Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>Example
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus
Note that the height of each column is auto-balanced, as per the spec.
Also note this demo and sample code is using moz and webkit vendor prefixes, should only work in Gecko (Firefox 1.5+, et al.) and Webkit (Safari 3+, Chrome, et al.) browsers. No native support in Internet Explorer or Opera yet that I know of.
All Related Properties
.three-col {
-moz-column-count: 3;
-moz-column-gap: 20px;
-webkit-column-count: 3;
-webkit-column-gap : 20px;
-moz-column-rule-color: #ccc;
-moz-column-rule-style: solid;
-moz-column-rule-width: 1px;
-webkit-column-rule-color: #ccc;
-webkit-column-rule-style: solid ;
-webkit-column-rule-width: 1px;
}You can also set the column-width (with prefixes) but it generally makes more sense to let it auto calculate that.
The rule ("rule", as in, a line) will split the gap down the middle. You can use the same values as you would a border.
Take care not to have your text blocks be so enormously tall that they are taller than a (fairly small) browser window, otherwise it's the same problem as text being wider than the browser window (scrolling back and forth to read = sucks). Also consider text-align: justify;
JavaScript Fallback
Is presented in this A List Apart article.
just ordinary question like always :-)
is IE also compatible with this column-count?
thanks
He says in the article..
“sample code is using moz and webkit vendor prefixes, should only work in Gecko (Firefox 1.5+, et al.) and Webkit (Safari 3+, Chrome, et al.) browser”
It looks like IE is not a compatible browser at this time.
Still, it degrades nicely to a single column – yet again, IE users get the information in a logical, normal manner, just not as visually pleasing!
It works in IE with the JS fallback.
The ALA article was from 2005. I wonder if anyone has come up with any new fallback scripts in the last six years. Mainly for IE since probably 99.9997% of other CSS browsers in use these days probably support the multi-column layout module.
who cares of IE6 :P
IE is losing market anyway.. bring on the CSS2.1 + :)
good, nice artical
This seems to work in the latest version of Opera. Using Opera 11.10 and Dragonfly I was able to apply the css. Here is a <a href="http://dl.dropbox.com/u/886672/css-tricks/multiple-columns-works-in-opera.png">screenshot</a>
Oops looks like I mangled that lets try this: http://dl.dropbox.com/u/886672/css-tricks/multiple-columns-works-in-opera.png
Does this work with just text? Or can one use images along with text? Fairly newcomer so excuse the seemingly silly ?