views:

348

answers:

10

hi,

I'm looking for a columnizer plugin (making columns of my small divs).

It is very important it has the following features:

1) It has to be as light as possible (if it is only css would be great, but I guess it is difficult make it work on IE then...)

2) It has to be cross-browser (I don't need IE6... IE7 and IE8 compatibility is required).

3) The divs has not to be broken. In other terms, the nodes have to be moved to next block but not splitted in 2. The nodes are div elements, they might include other divs, images and text.

4) The column have to have a fixed width and fixed margin. This means that when I resize the browser, and new columns are created (become the window becomes wider), the new columns have to rigidly keep the same width and distance between them. (margin:20px) (width:200px)

5) The content is dynamic. I'm using drupal as CMS. My customer can add or remove nodes, so I need a dynamic solution.

Would be great to have some css.. but I'm afraid I need some jQuery plugin because I need all 4 features being supported.

I found several plugins and css styleshits with very good solutions, but I couldn't find a complete one.

Thanks

+3  A: 

How about 1KB Grid CSS Framework? It's the simplest CSS framework and it is highly customizable.

A sample stylesheet looks like this:

/* 1KB grid - 12 columns, 60 pixels each, with 20 pixel gutter */
.g1{width:60px;}.g2{width:140px;}.g3{width:220px;}.g4{width:300px;}.g5{width:380px;}.g6{width:460px;}.g7{width:540px;}.g8{width:620px;}.g9{width:700px;}.g10{width:780px;}.g11{width:860px;}.g12{width:940px;}
.column{overflow:hidden;float:left;display:inline;margin:0 10px;}
.row{width:960px;overflow:hidden;margin:0 auto;}.row .row{width:auto;display:inline-block;margin:0 -10px;}

And the HTML looks like:

<div class="row">
    <div class="column g4">...</div>
    <div class="column g4">...</div>
    <div class="column g4">...</div>
</div>
XaviEsteve
thanks for the link. I'm afraid it doesn't satistfy point 4 (second part). New columns have to be created when the browser is resized in order to fill all the window area when this becomes wider.
Patrick
In other words, the columns should be dynamic. If the browser window is small, I have few columns, if it is big I have many columns
Patrick
Oh, now I get what you mean. Just change the `.row` to `{width:100%}`. I've coded it here: http://jsfiddle.net/hGeBH/
XaviEsteve
mhm I'm afraid this still doesn't solve my issue, because my html code is not changing, I mean.. the nodes are not automatically assigned to different columns divs. In other words the HTML code needs to be changed by some javascript code in order to create the columns divs.
Patrick
Depending on the browser window the columns need to have more or less articles. The more the columns, the less articles for column. And it has to be updated when the browser window is resized.
Patrick
+1  A: 

I have read your list of requirements (but, I must admit, I may not have completely understood them), but, based on what I have understood, I would suggest a jQuery plugin called "Easy List Splitter".

jQuery plugin: Easy List Splitter | Andrea Cima Serniotti

Not sure how many of your requirements this may satisfy, but, at the least, it may provide a suitable base from which to hack a customised solution.

Lucanos
+1  A: 

Have you tried this before: http://welcome.totheinter.net/columnizer-jquery-plugin/

I've used it before and found it very easy to set-up - but obviously YMMV :)

Ian Oxley
A: 

It sounds like you're looking for a grid view for the nodes. Take a look at this Table-Free Gallery View in Drupal tutorial. Basically, the key idea is to use inline-block divs to create the columns that you need.

If you don't want vertical spaces in between the spaces (to make it look like columns), do not set margin-bottom as shown in the example, or set it to margin-bottom: 0. You can also create the column lines by adding left and right borders with CSS: border-left: 1px solid black; border-right: 1px solid black;

Also, you should be using Views in Drupal for this. Although it isn't necessary, it gives you more control over the display.

sirhc
A: 

In other words, the columns should be dynamic. If the browser window is small, I have few columns, if it is big I have many columns – Patrick May 9 at 17:28

im not sure you can accomplish this with just css, as you are adding removing elements and flowing content. i think you will have to resort to JS

David Morrow
+4  A: 

I think you want to be using CSS inline-block. That will satisfy your requirements as far as I understand them. Each column will just appear one after the other across the page and wrap onto the next line wherever appropriate.

CSS

.col {
    display: inline-block;
    /* could add `display:-moz-inline-box` for Firefox 2 compatibility */
    vertical-align: top;
    width: 200px;
    margin-right: 20px;
}

HTML

<div class="container">
    <!-- using span instead of div for IE6 compatibility -->
    <span class="col">1st block</span>
    <span class="col">2nd block</span>
    <span class="col">3rd block</span>
    <span class="col">4th block</span>
</div>

If there are major problems in IE6-7 you could try ie7.js which should fix them.

DisgruntledGoat
@Patrick: note that IE7 requires natural inline elements to accept inline-block... so, you have to use spans as a column-wrapper. You can put the node divs inside the spans, if you must have divs wrapping the nodes. See http://www.quirksmode.org/css/display.html#t03
ANeves
+1, but make sure to add `.container { white-space: nowrap; }` so that the columns don't wrap to the next line and keep side-to-side. See http://www.quirksmode.org/css/whitespace.html
ANeves
Reading further, it seems OP may wish for columns to be added or removed automatically when `.container`'s size changes - I've asked him to clarify. **If** so, this answer needs to be completed with a bit of JS to add or remove columns on resize.
ANeves
@ANeves: That's not necessarily the case - you can effectively emulate `inline-block`, even in IE6 for block elements: http://foohack.com/2007/11/cross-browser-support-for-inline-block-styling/ (it requires hacks though)
David Morrissey
Well, yes. But if you can simply avoid hacks, the merrier.
ANeves
@ANeves: Maybe you're missing the point. The columns are *supposed* to wrap onto the next line (see the link Patrick posted: http://donatellabernardi.ch/drupal/ ). You don't need javascript to do anything when the window resizes, the browser does all the work making the columns fit onto each line.
DisgruntledGoat
@DisgruntledGoat: maybe. But OP said `Depending on the browser window the columns need to have more or less articles. The more the columns, the less articles for column. And it has to be updated when the browser window is resized.` on http://stackoverflow.com/questions/2795266/css-javascript-multiple-columns/2875080#comment-2885944 - doesn't that mean he wants the number of columns to change dynamically? It's confusing.
ANeves
@ANeves: That is exactly what my answer does. Making things inline-block means they run just like regular text or images. When the browser is wider then more "columns" fit on each line. Floating the blocks gives a similar effect, however the layout will break if the columns are different heights.
DisgruntledGoat
@DisgruntledGoat: yes, I understand that. Since your answer is marked as solution, I guess that really **is** what OP was after. He could have answered the comments though. =| (Not to mention fixing the question so that whomever reads this thread can understand it better...)
ANeves
+1  A: 

Hi, have you had a look at the jquery-masonry plugin. Automatically creates columns, with fixed width & consistent margin.

Here's a demo

dalton
+1  A: 

Just float them all left. Works in all browsers from IE6 and on.

Here's an SSCCE.

<!doctype html>
<html lang="en">
    <head>
        <title>SO question 2795266</title>
        <style>
            .nodes div {
                float: left;
                width: 200px;
                margin: 10px; /* Or set right and bottom to 20px. */
                border: 1px solid black; /* Just for visibility. */
            }
        </style>
    </head>
    <body>
        <div class="nodes">
            <div>node</div>
            <div>node</div>
            <div>node</div>
            <div>node</div>
            <div>node</div>
            <div>node</div>
        </div>
    </body>
</html>
BalusC
hi, point (3) is not satisfied
Patrick
Then I apparently don't understand point 3. Can you please clarify this point more? Did you mean something special with "not splitted in 2"? This does basically the same as the solution of DisgruntledGoat, but is better crossbrowsercompatible.
BalusC
@BalusC, can you explain how it is "better crossbrowsercompatible" than @DisgruntledGoat 's answer?
ANeves
A: 

There are a pile of jQuery plugins which specifically deal with spreading content across a number of columns:

In addition to jQuery plugin: Easy List Splitter | Andrea Cima Serniotti, which I already mentioned in an earlier Answer, there are the following:

One of them should do the trick.

Lucanos
A: 

Then you want the jquery masonry plugin.

Go to my test site - http://jasondaydesign.com/masonry_demo

You will see I have 2 different box sizes (width) that lay around each other. You can do this with one column size instead, just for the purposes of my sandbox I was playing with two.

When you resize the browser, the boxes will rearrange themselves accordingly.

It's a brilliant script.

Good Luck!

Jason