tags:

views:

83

answers:

7

Given a

<div>
Lorem ipsum dolor sit amet, consectetur adipiscing...
</div>

is it possible with CSS to generate a 2 or 3-column layout automatically, say by specifying the height of the container? If not, what are best practices in such a case?

Thanks for your help.

A: 

This question belongs at Doctype. Please read the faq.

Tim McNamara
Browsing through Doctype, there seem to be more design-oriented questions here. I was really wondering if there is a specification in the CSS standard for this, or any other way (not CSS). Maybe python is the way to go? :)
Michael
Why go through all the resources and effort using Python to create a column layout? Straight CSS will work wonders if you let it. Besides, using Python or PHP or whatever your choice, ultimately it's all going to be css based in the end.
webfac
you're absolutely right. The thing is, if I have a very long text, and have to split it into several columns I may (A) specify explicitly where to split them or (B) what I'm asking here, to do it dynamically by CSS.
Michael
@Michael Ok first off, you cannot use CSS to automate the column process, however you could use a server side language to determine WHERE to add the columns, split your text and insert it into the columns.
webfac
A: 

The Floatutorial website has good examples of best practice.

Martin Clarke
they explicitly break the page, where the second column must start. Unfortunately :(
Michael
A: 

See if this is any use..

Adam
+2  A: 

You most certainly could not turn the above into a 2 or 3 column layout, however if you had a container and 3 divs, creating a 3 column layout would be as simple as this:

<div class="container">

  <div class="col1">Column1</div>
  <div class="col2">Column2</div>
  <div class="col3">Column3</div>

</div>

And the CSS:

.container{overflow:hidden; padding:20px; border:1px solid #ccc;}
.col1, .col2, .col3{width:200px;float:left;clear:none;margin:0 10px 0 10px;}

This would create a VERY basic 3 column layout with each column having 10px of margin on each side. The container div has 20px padding and a subtle border.

Hope this points you in the right direction.

webfac
what makes you certain, that there is no way to do this? When you have long texts, then automating the breaking of the page would be nice. But your help is highly appreciated +1 upvote
Michael
My Apolgies, I misunderstood the question then, I meant you CANNOT turn a single DIV into a 3 col layout unless you had spans or ANY other block elements within that you could manipulate via CSS.
webfac
And I guess you could use PHP (or other language) to split the text up into chunks (at user defined word lengths) then insert divs, style them as columns and replace the text into them, all on server side. But I assure you it's going to be trivial.
webfac
BTW this article (and site) is a great stop for CSS column info: http://www.alistapart.com/articles/fauxcolumns/
webfac
+1  A: 

For this type of thing I would look at using a grid system such as 960 or YUI

Both include ways to divide subsections into columns.

David Dorward
I've quickly skimmed through both, but haven't found the explicit reference yet. Just to make sure: you give it a text as input (without specifying where it should break), and it gives you a 2-column layout as output?
Michael
Great suggestion, I use the 960 grid system often, and coupled with the CSS reset by Meyerweb (http://meyerweb.com/eric/tools/css/reset/), you can't go wrong, even IE6 welcomes you with arms wide open!
webfac
@ Michael NO, you still have to manually define the column in your markup such as <div class="grid_5"></div> which spans FIVE grids wide, you can choose a container of 12 grids, 18, 24 etc
webfac
@ Michael I think you need to change the title of the post to indicate your desire for AUTO COLUMNS
webfac
+1  A: 

Given comments on my previous answer, it seems that I may have misunderstood what you were looking for.

If you want text to automatically flow from one column to another then your options are:

Personally, I would avoid it. In general, content that flows from one column to the next is quite screen-media-unfriendly.

David Dorward
And near in mind that CSS3 is still not as widely used as we'd like to think it is. The majority of your internet market are still using outdated browsers. Be careful.
webfac
Hence "poorly supported"
David Dorward
awesome, thanks David. now if I could only upvote this. Too little reputation :(
Michael
You should be able to accept it by clicking the tick near the score (if you think it best answers the question)
David Dorward
+2  A: 

You can always take the jQuery approach, look at this article: http://www.mainelydesign.com/blog/view/auto-columns-columnizer-my-new-favorite-jquery-plugin

webfac
Great plugin. The link to the actual plugin site is http://welcome.totheinter.net/columnizer-jquery-plugin/
Bennett McElwee