Results 1 to 9 of 9

Thread: how to make div's with different heights automatically divide into three columns?

  1. #1
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to make div's with different heights automatically divide into three columns?

    My question is rather simple:

    I have several divs as follows

    Code:
    <div id="wrapper">
     <div class="left">...</div>
     <div class="middle">...</div>
     <div class="right">...</div>
     <div class="left">...</div>
     <div class="middle">...</div>
     <div class="right">...</div>
     <div...
    </div>
    And the css looks like this:
    Code:
    #wrapper { width:910px; }
    
    .first, .middle, .last { width:300px;  float:left; clear:none; }
    .first { margin-right: 5px; clear:both; }
    .middle { margin-right: 5px; }
    Now, this gives me the divs in 3 nice columns, but the divs all have different heights, and the next row only starts after the longest div of the previous row ends. How can I make it, so that there are no irregular spaces between the divs of the same column?

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I would suggest giving all the divs a fixed height but I'm not entirely sure if this is the overall effect you'd like to achieve - can you provide a diagram to illustrate what you want versus what is currently happening?

    How about a sample page link too? Its probably easier if you provide a (non)working mock-up to help explain the problem you describe.
    Last edited by Beverleyh; 09-28-2012 at 03:13 PM.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, there is a different amount of content in each div, that's why they can't all have the same size.
    here is a link: http://hddevelopement.funpic.de/test/divs.html

    This is what it looks like now:
    ___ ___ ___
    ## ## ##
    ## ## ##
    ## ##
    ## <-- the longest div from the first row ends,
    ___ ___ ___
    ## ## ## <-- and all following divs start at the same "height"
    ## ## ##
    ## ##
    ##

    However, it should look like this:
    ___ ___ ___
    ## ## ##
    ## ## ##
    ___ ## ## <-- as soon as the div stops, another one begins
    ## ## __
    ## ___ ##
    ## ## ##
    ## ##
    ##
    .
    .
    .

    Hope, that is understandable.

    It would be even better, if this could be achieved with div's that all have the same style, but that's secondary.

    I thought it could maybe be done by changing the "clear" or "position" attribute, but I wasn't able to achieved the desired effect.

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Probably a good idea to take the full screen popup ads off your test page...
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. #5
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ha! I wish, but I'm using a free hosting server for the test page which automatically inserts those.

    Anyway, they have no effect on the problem. It also occurs in offline testing in all browsers.

    Do you have any Idea, what the problem might be? I thought it was something simple I just wasn't aware of

  6. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I'm still not sure, but is sounds like you want something like this?
    Click image for larger version. 

Name:	3-div-cols.jpg 
Views:	343 
Size:	12.8 KB 
ID:	4776

    3 div columns with varying height divs within each?

    If so, you're approaching the markup from the wrong angle.

    Start with the 3 main/outer div columns and then stack you inner divs inside them;

    Code:
    <div class="yellow"> 
        <div>cat</div>
        <div>dog</div>
        <div>mouse</div>
    </div>
    <div class="purple"> 
        <div>red</div>
        <div>green</div>
        <div>yellow</div>
    </div>
    <div class="pink"> 
        <div>small</div>
        <div>medium</div>
        <div>large</div>
    </div>
    Is this what you mean?
    Last edited by Beverleyh; 09-28-2012 at 04:17 PM. Reason: class colours
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  7. #7
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hm, yes. The outcome is exactly what I want. However, I was hoping that it could be approached without separating the content-containing-divs into three parent divs. Do you think thats possible?

  8. #8
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I dont believe so - I think you would need the 3 containing divs for linear structure otherwise shorter divs will always float up against higher ones (on their left) and only break onto a new line after the highest one on that row allows the following divs to clear.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  9. #9
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Okay, I see. Thank you for your help!

Similar Threads

  1. Make Columns Equal
    By SChaput in forum CSS
    Replies: 2
    Last Post: 07-03-2009, 06:37 PM
  2. Divide table to pages
    By d-machine in forum JavaScript
    Replies: 7
    Last Post: 10-21-2008, 06:31 AM
  3. change div heights
    By lord22 in forum JavaScript
    Replies: 7
    Last Post: 07-26-2008, 04:17 AM
  4. img divide in links
    By chechu in forum HTML
    Replies: 18
    Last Post: 03-01-2007, 04:54 PM
  5. automatically make an rss feed.
    By queerfm in forum HTML
    Replies: 0
    Last Post: 12-24-2006, 02:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •