Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts

    Give a div 100%height of the div it is inside of when container has no fixed height

    Let's say i have a div that is 100% wide, but has no fixed height.

    Then inside of this div you have two columns with no fixed height, but the left columns is always going to be taller based on content.

    What is the best way (if at all possible) to tell the shorter right column to take up 100% of the containers height.

    Is this even possible. How can you get 100% of nothing?

    Appreciate any help, thanks.

  • #2
    Registered User
    Join Date
    Jun 2011
    Posts
    1,063
    Thanks
    12
    Thanked 241 Times in 240 Posts
    You can't unless you used absolute positioning, faux columns, or JavaScript to detect the height of the parent.

    Absolute Positioning:

    Code:
    #container {
        position: relative;
        width: 600px;
    }
    #short-column {
        position: absolute; top: 0; left: 0;
        width: 300px;
        height: 100%;
    }
    #long-column {
        margin-left: 300px;
    }
    Faux Columns:

    Code:
    #container {
        width: 900px;
        background: #ddd; /* this background will show up for the short-column */
    }
    #short-column {
        float: left;
        width: 300px;
    }
    #long-column {
        overflow: hidden;
        background: #fff; /* this background is just masking the parent's background */
    }
    http://www.alistapart.com/articles/fauxcolumns/

    Almost everyone uses faux columns especially Google.

    ----------------------------

    All the solutions: http://css-tricks.com/fluid-width-equal-height-columns/
    You can also make the background for your "short-column" a border: http://woorkup.com/2009/10/11/really...eight-columns/ (pretty stupid though)
    Last edited by Sammy12; 09-29-2012 at 01:34 AM.

  • #3
    New Coder
    Join Date
    Sep 2012
    Location
    Scottish Borders
    Posts
    36
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Hi, my personal way of doing what you require is
    Code:
    #container{width:100%;overflow:hidden;}
    #longcolumn{float:left;width:49.5%;overflow:auto;}
    #shortcolumn{float:right;width:49.5%;overflow:auto;padding-bottom:20em;margin-bottom:-20em;}
    The 20em figure is variable and only has to be enough to cover the difference between the long and short column content difference. The figure used must be the same with padding having a plus value and the margin having a negative value.
    If the situation arises where you do not which column would be the shorter then you would give both columns the plus padding - minus margin instruction. Jim


  •  

    Posting Permissions

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