views:

841

answers:

4

I am trying to float columns using css so they stack up evenly like on this blog: http://typeneu.com

It seems to be impossible using css so I am looking in to javascript.

The website listed above uses this javascript file: http://typeneu.com/wp-content/themes/grid-a-licious/scripts/grid-a-licious.js

I have tried to implement it to experiment but it doesn't seem to be working...

any links to tutorials on this subject or suggestions for getting it to work with javascript or css?

Edit: I would like the number of columns to be flexible with the screen resolution.

thanks!

A: 

That javascript file is actually part of this theme:

http://suprb.com/grid-a-licious/

It's not that hard to do in CSS, however. You just need to use floats.

For example:

<div style="float:left">Hello</div>
<div style="float:left">I'm also saying hello</div>
<div style="clear:both;"></div>
<div style="float:left">Hi again</div>
<div style="float:left">From the second line, that too!</div>
<div style="clear:both;"></div>

See what I mean? :)

Salty
-1: Floated elements without explicit widths are evil.
Triptych
Point taken. I know that already, but I guess I should have mentioned that, just in case someone reading it doesn't learn that as well. :P
Salty
A: 

I have a site which basically has DIV's float left with a set pixel width. Depending on the resolution and window size I might have 1-n columns, You should be able to basically: .myClass { float:left; width:350px; }

my content more content even more content

To get a fixed number of columns I'd assume you can calculate the width using javascript or perhaps there is some other trick.

Edit

Ok looking at their JS file you need to make sure you match up your class and id's to match what they are expecting Looks like all your posts need to be ina div with an id of allposts.

Check out the HTML of the site you typenu site you referenced and get your html to match theirs.

JoshBerke
The problem with that is if you have different heights for each post there are gaps left when you go to the next row.. where as it is all filled in with this example: http://typeneu.com
but thanks for the reply
A: 

thanks for the reply. the problem with css is that if there is a longer column on the left the space below the right column is not filled by the next post. you can see if you scroll down a bit on my blog: http://www.joehamilton.info/00parked/sales/ (under construction)

I saw the grid-a-licious theme but have not been able to take the javascript from that theme and get it to work in my theme.

hmmm ohhh I see so yep ok this is an interesting challenge if I find something I'll be back
JoshBerke
A: 

Keep it simple. This should make a nice page... the css should include this:

 .header,.bod,.footer { width: 700px; margin: 0 auto; }
 .header { border-bottom: 3px solid #CCC; margin-bottom: 1.0em; }
 .footer { border-top: 3px solid #CCC; padding-top: 1.0em; }
 .first, .second, .third, .fourth { position: absolute; top: 0; left: 0;}

 .first    { width: 100px; left:10px;}
 .second   { width: 100px; left:110px;}
 .third    { width: 100px; left:220px;}
 .fourth   { width: 100px; left:330px;}

 .clear,.tall { position: relative; } /*\*/* html .clear{ display: inline;}
 .tall:after { content: ''; } /*fix of safari bug?*/

and some html (inside the body, after you have called the css):

 <body>
 <div class="header">TITLE</div>
 <div class="bod clear">
 <div class="first tall"> Lorem ipsum </div> 
 <div class="second"> Lorem ipsum </div> 
 <div class="third"> Lorem ipsum </div> 
 <div class="fourth"> Lorem ipsum </div> </div>
 </div>
 <div class="footer" >FOOTER</div>
 </body>
 </html>

Simple, works, right?

Alex
Thnks for the rply Alex. I would like the number of columns to be flexible with the screen res so that would not work. I think I will have to try adapting the javascript inc with the theme: http://suprb.com/grid-a-licious/Thanks again and any more suggestions for doing this via css appreciated!