+ Reply to Thread
Results 1 to 3 of 3

Thread: Expand div height to fit parent

  1. #1
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Expand div height to fit parent

    HTML Code:
    <div class="singlewhiteBox_body floatContainer" id="textbook">
                <script>
                   $(document).ready(function() {                
                      $('.row, .lastRow').hover(function() {
                         var ID = $(this).attr('id');
                         //alert(ID);
                         $('#'+ID+' .class').toggleClass('class_hover');
                      }, function() {
                         var ID = $(this).attr('id');
                         $('#'+ID+' .class').toggleClass('class_hover');
                      });
                      
                      $('.chapter').hover(function() {
                         $(this).toggleClass('chapter_hover');
                      }, function() {
                         $(this).toggleClass('chapter_hover');
                      });
                   });
                </script>
             <div class="left">
                <div class="row" id="CK1">
                   <div class="class">CK1</div>
                   <div class="chapterContainer">
                      <a href=""><span class="chapter">二十二 &nbsp;&nbsp; 二十三</span></a>
                      <a href=""><span class="chapter">二十二 &nbsp;&nbsp; 二十三</span></a>
                      <a href=""><span class="chapter">二十二 &nbsp;&nbsp; 二十三</span></a>
                      <a href=""><span class="chapter">二十二 &nbsp;&nbsp; 二十三</span></a>           
                   </div>
                </div>
                <div class="lastRow" id="CK2">
                   <div class="class">CK2</div>
                   <div class="chapterContainer">
                      <a href=""><span class="chapter">二十二 &nbsp;&nbsp; 二十三</span></a>
                      <a href=""><span class="chapter">二十二 &nbsp;&nbsp; 二十三</span></a>
                      <a href=""><span class="chapter">二十二 &nbsp;&nbsp; 二十三</span></a>
                      <a href=""><span class="chapter">二十二 &nbsp;&nbsp; 二十三</span></a>           
                   </div>
                </div>
             </div>
             <div class="right">
                
             </div>
             </div>
    Code:
    #textbook .left, #textbook .right {
       border: 1px solid #777777;
       border-top: 4px solid #777777;
       border-bottom: 4px solid #777777;
       width: 49%;
    }
    #textbook .row, #textbook .lastRow {
       width: 100%;
       text-align: center;
       padding-bottom: 0; /* ALERT */
       border-bottom: 2px solid #777777;
       color: #000000;
    }
    #textbook .lastRow {
       border: 0;
    }
    #textbook .row:hover, #textbook .lastRow:hover {
       background: #ffd899;
    }
    #textbook .row .class, #textbook .lastRow .class {
       width: 55px;
       height: 100%;
       position: relative;
       font-size: 20px;
       border-right: 2px dashed #777777;
       margin-right: 10px;
       float: left;
    }
    #textbook .row .chapterContainer, #textbook .lastRow .chapterContainer {
       width: 362px;
       float: right;
       text-align: left;
    }
    #textbook .row .chapterContainer a, #textbook .lastRow .chapterContainer a {
       text-decoration: none;
    }
    #textbook .row .class_hover, #textbook .lastRow .class_hover {
       background: #FF9900;
       border-right: 2px dashed #FFFFFF;
       color: #FFFFFF;
    }
    #textbook .row .chapter, #textbook .lastRow .chapter, #textbook .row .chapter a, #textbook .lastRow .chapter a, #textbook .row .nochapter, #textbook .lastRow .nochapter {
       text-decoration: none;
       width: 124px;
       height: 19px;
       margin-right: 2px;
       color: #000000;
    }
    #textbook .row .chapter_hover, #textbook .lastRow .chapter_hover, #textbook .row .chapter_hover a, #textbook .lastRow .chapter_hover a {
       background: #FF9900;
       color: #FFFFFF;
    }
    How do I get div.class to expand to the full height of div.row and div.lastRow?

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Expand div height to fit parent

    In this case, I'd position them absolutely behind the .chapterContainer (actually, given that the .chapterContainer are floated, you don't need to worry too much about the "behind"). Note there are some other fixes that need to be made:

    Code:
    #textbook .row /* Not bothering with .lastRow (see recommendation below) */ { 
        position: relative; /* create new containing block for .chapterContainer */
        overflow: auto; /* contain floated children */
    }
    
    /* Damn you, IE 6. Why won't you let me use child selectors? */
    #textbook .row /* > */ div.class {
        position: absolute;
        top: 0;
        left: 0;
        /* in IE6, setting "bottom" won't work, so set "height" instead. */
        height: 100%;
    }
    #textbook .chapterContainer {
        position: relative;
        z-index: 1;
    }
    I also recommend adding a "row" class to .lastRow, so you don't need to target .row and .lastRow separately (notionally, a .lastRow is also a .row, so it should have both classes). Once you don't have to support IE6, you can drop the .lastRow completely, and use .row:last-child whenever you need to select the last row.
    Last edited by misson; 12-21-2009 at 06:21 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Expand div height to fit parent

    once again, thanks misson!

    I just made a few tweaks to prevent a scroll bar from popping up so I can add a margin-top to .class

    Code:
    /* TEXTBOOK (#textbook) */
    #textbook .left, #textbook .right {
       border: 1px solid #777777;
       border-top: 4px solid #777777;
       border-bottom: 4px solid #777777;
       width: 49%;
    }
    #textbook .row {
       width: 100%;
       text-align: center;
       padding-bottom: 0; /* ALERT */
       border-bottom: 2px solid #777777;
       color: #000000;
       position: relative;
       overflow: hidden;
    }
    #textbook .lastRow {
       border: 0;
    }
    #textbook .row:hover, #textbook .lastRow:hover {
       background: #ffd899;
    }
    #textbook .row .class, #textbook .lastRow .class {
       width: 55px;
       height: 100%;
       position: absolute;
       top: 0;
       left: 0;
       font-size: 20px;
       border-right: 2px dashed #777777;
       margin-right: 10px;
       padding-top: 10px;
       float: left;
    }
    #textbook .row .chapterContainer, #textbook .lastRow .chapterContainer {
       width: 362px;
       min-height: 40px;
       float: right;
       text-align: left;
       position: relative;
       z-index: 1;
       padding: 5px 0 5px 0;
    }
    #textbook .row .chapterContainer a, #textbook .lastRow .chapterContainer a {
       text-decoration: none;
    }
    #textbook .row .class_hover, #textbook .lastRow .class_hover {
       background: #FF9900;
       border-right: 2px dashed #FFFFFF;
       color: #FFFFFF;
    }
    #textbook .row .chapter, #textbook .lastRow .chapter, #textbook .row .chapter a, #textbook .lastRow .chapter a, #textbook .row .nochapter, #textbook .lastRow .nochapter {
       text-decoration: none;
       width: 124px;
       height: 19px;
       margin-right: 2px;
       color: #000000;
    }
    #textbook .row .chapter_hover, #textbook .lastRow .chapter_hover, #textbook .row .chapter_hover a, #textbook .lastRow .chapter_hover a {
       background: #FF9900;
       color: #FFFFFF;
    }
    +REP
    Last edited by diabolo; 12-21-2009 at 09:48 PM.

+ Reply to Thread

Similar Threads

  1. CSS footer way down the page.
    By queentoad in forum Programming Help
    Replies: 10
    Last Post: 06-05-2009, 08:14 AM
  2. 100% height with CSS
    By Ixonal in forum Graphics & Webdesign
    Replies: 11
    Last Post: 03-08-2009, 06:28 PM
  3. CSS Errors
    By djcustom in forum Programming Help
    Replies: 2
    Last Post: 01-21-2009, 02:12 PM
  4. help!!!!!
    By lordsofvine in forum Programming Help
    Replies: 1
    Last Post: 10-15-2008, 05:00 AM
  5. can anyone convert a CSS into an IPB skin for me?
    By leafypiggy in forum Programming Help
    Replies: 0
    Last Post: 05-06-2008, 07:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers