Need Hosting? Get discounted hosting from Hostmonster now.

Latest Tweets from Kreeaytiv

Like Kreeaytiv on Facebook

+1 Kreeaytiv on Google

Contact Kreeaytiv

Interested in a quote from Kreeaytiv? Have a question about a project? Feeling lonely? Use the form below!








Columns with CSS3? Yup!

"Rupert Murdoch is on my driveway" by kevindooley via Flickr

"Rupert Murdoch is on my driveway" by kevindooley via Flickr

I had no idea CSS3 did this!

For any of you who mess with CSS, you know that building a mutli-column layout can be tricky, especially when you’re doing it for sites that run on a CMS of some sort. But a little CSS3 I just discovered makes things quite a bit easier…

.content {
-moz-column-count: 3;
-moz-column-gap: 10px;
-moz-column-rule: none;
-webkit-column-count: 3;
-webkit-column-gap: 10px;
-webkit-column-rule: none;
column-count: 3;
column-gap: 10px;
column-rule: none;
}

So, assuming you’ve got a div with the class “content”, and assuming you’ve got a whole mess of text inside of that div, the above code will automatically arrange that text in to 3 multiple columns, with a gap (i.e. margin) of 10px, with no rule (i.e. line, or, more CSS-ly, border).

That’s it!

It won’t solve all of your multiple column layout woes, but, it will definitely work for quite a few different situations. And it’s so easy!

A few quick notes… first, this won’t work quite yet in Internet Explorer (surprise). So for now, you’ll either have to use this in a progressively enhanced way, or, simply ignore those less fortunate IE users altogether. This is why the rules are duplicated with the “-moz” and “-webkit” prefixes… “-moz” makes Firefox kick this right, “-webkit” makes Chrome/Safari bust it correctly. One day, though, CSS3 will actually be the standard, and then the last 3 lines will work everywhere. Just write things like they are above and ensure you won’t have to go updating your code later on.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>