Results 1 to 9 of 9

Thread: dynamically positioning 3 columns.

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default dynamically positioning 3 columns.

    I have a centered div of width 66% of browser width. Inside this div are three divs labeled column 1, column 2, and column 3.

    I would like the first column to float left.
    The third column should float right.
    The middle column should be centered between the two. All of the columns are 32% in width. That is 32% of the 66%. This should give the illusion of 2% wide space between column 1 and column 2 and another 2% wide space between column 2 and column 3.

    Here is the overly complicated demo I have. As you can see it is close, but still not quite right.
    Last edited by james438; 10-30-2011 at 04:01 AM.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There are other ways to line up the three divs. I don't know what's best, but you could play with a few combinations. For example, create three divs that are all float:left. The first and last are 32%, and the middle one is 36%. Then inside that middle one you can center a div that has a small border (whatever that math is) on both sides.
    Or you could just use float:left on all of them and add a left-margin to two of them.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Good thought, however you then run into the problem in half the browsers where an aggregate width of 100% is not always 100%.
    To choose the lesser of two evils is still to choose evil. My personal site

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    If you want a small border between the sections, it seems like you have some room to play with it. Not sure how much that helps. Otherwise, I'm not sure what's wrong the CSS. Sorry I can't be of more help.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    No worries. This project is just a "passing the time" activity for me. traq mentioned that different browsers handle percentages differently and round values up or down or differently hence the problem we have here.

    I figure that the best way to handle it is to float the right div to the right and the left div to the left and then relatively position the middle div to give the illusion that it is centered as opposed to being actually centered. If it is actually centered then the three divs which are all positioned differently seem to interact with each other poorly.

    In the demo page I gave the border that peeks out to the right. I am hoping to get that missing width to be shared between the margins to the left and right of the middle div. I am sure I am not making the best sense in this paragraph.

    I wish this error was not noticeable in its current format. At first I thought it was a bug in the Opera browser, but then I was convinced otherwise.
    To choose the lesser of two evils is still to choose evil. My personal site

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    have a look at some of the fluid layouts here on DD - this one, for example: the left and right columns are floated, and the center column has no defined width: just left and right margins that match the widths of the left and right columns.

  7. #7
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I think that may be the solution traq. The idea of using negative margins in percentages is somewhat foreign to me. Using negative margins in conjunction with positive widths for a total value of positive 20% just doesn't add up for me, but it does work in DD's example.
    To choose the lesser of two evils is still to choose evil. My personal site

  8. #8
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I understand the negative margins now a little better. The middle column is actually behind the other two columns and stretches the entire width of the parent div as opposed to 65%. When I saw that I set the right and left margins of the "middle" column to 35% to create the illusion of a buffer between the three columns.
    To choose the lesser of two evils is still to choose evil. My personal site

  9. #9
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by james438 View Post
    I understand the negative margins now a little better. The middle column is actually behind the other two columns and stretches the entire width of the parent div...
    exactly right.

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
  •