Div doesn't expand for content, help?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AJM Project
    New Member
    • Aug 2008
    • 10

    Div doesn't expand for content, help?

    Hello,

    I see this is a well known thing and have seen many answers but none have worked for me. It's just a test page I'm making and I've ran into this so I thought I'd ask how to fix it - inline & embedded CSS just now as It's just a quick test page I'm working on. Basically I've got my container div, two other div columns inside with fixed widths. In the 2nd column I have 2 divs, one is under the other, which exceeds the size of the browser. Anyway, that's fine, but the containerdiv doesn't expand by the browser size. I want it to go right down and expand to whatever, but it won't.
    Some solutions I've tried:

    . Adding an extra div with clear:both
    . Adding overflow:hidden in the container (It hides the rest of the browser and doesn't let me scroll down)
    . Taking the height:100% attribute out of the body, the container and html selectors to see if it extends automatically

    No luck on all costs. The container div is just stoppping at the size of the browser, doesn't go underneath when i scroll.


    Here's my code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>sfkdgbgdsf</title>
    <style type="text/css">
    html {
    height:100%;
    }
    
    .funkybox {
    background-color:black; 
    color:gray; 
    border-style:thin solid; 
    border-width:1px; 
    border-color:red;
    }
    
    .boxbg {
    background-color:black;
    color:gray;
    }
    </style>
    
    
    </head>
    
    <body style="height:100%; margin-top:0px; margin-bottom:0px; background-color:#262626; text-align:center; color:white;">
    
    
    
    <div id="container" style="width:900px; height:100%; margin-left:auto; margin-right:auto; background-color:black; background-position:center;">
    
    
    
    <div style="height:6px;"></div>
    
    
    <div id="heading" style="font-family:'times roman', arial, verdana; font-size:1.5em; width:886px; height:50px; border-style:solid; background-position:center; margin-left:auto; margin-right:auto;  border-color:gray; border-width:1px; background-color:#262626; color:yellow; filter:alpha; opacity:60%; font-weight:normal; text-align:center; margin-bottom:10px; x; text-decoration:underline; padding-top:8px;">Andrew's CSS Test Page</div>
    
    <div id="left column" style="width:125px; float:left; margin-left:14px;">
    
      <div id="menu" style="width:125px; height:267px; background-color:black;          filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC;  border-width:1px; ">
    
    [B]Content
    [/B]
    
    
      <div style="width:125px; height:96px; background-color:black; filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC; border-width:1px; margin-top:10px; padding-top:4px;">
    [B] Content[/B]
      </div>
    
      <div style="width:125px; height:96px; background-color:black; filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC; border-width:1px; margin-top:10px; padding-top:4px;">
       [B] Content[/B]
      </div>
    
       <div style="width:125px; height:96px; background-color:black; filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC; border-width:1px; margin-top:10px; padding-top:4px;">
     [B] Content[/B]
       </div>
    </div>
    
    <div id="middle column" style="width:700; margin-left:10px; margin-bottom:0px; float:left; text-align:left;">
    
      <div style="width:590px; background-color:black; color:white; filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC; border-width:1px; padding:5px; line-height:25px;">
    [B] Content[/B]
      </div>
    
      <div style="width:200px; height:200px; background-color:white;">
      </div>
    
    
    
     </div>
    
    
    </div>
    </body>
    </html>
    Last edited by AJM Project; Aug 21 '08, 08:35 PM. Reason: spelling
  • David Laakso
    Recognized Expert Contributor
    • Aug 2008
    • 397

    #2
    Assuming I understood the question:
    Among other things, the markup was invalid, you neglected to enclose the floats, and closed the divisions in the wrong order.
    Corrections on the file below. Cursory checked local IE/6, IE/7, and compliant browsers.
    FWIW, it's a lot easier to de-bug a file that has all the styles embedded in the head of the document.


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta name="generator" content=
    "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
    <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
    
    <title>sfkdgbgdsf</title>
    <style type="text/css">
    /*<![CDATA[*/
       
          html {
       
          /*height:100%;*/
       
          }
           .funkybox {
      
          background-color:black;
      
          color:gray;
            border-style:thin solid;  
          border-width:1px;
          border-color:red;
            }
    
          .boxbg {
           background-color:black;
           color:gray;  
          }
     
    
     
    /*]]>*/
    </style>
    </head>
    
    <body style=
    "/*height:100%;*/ margin-top:0px; margin-bottom:0px; background-color:#262626; text-align:center; color:white;">
    <div id="container" style=
    "border:1px solid #fff; width:900px; height:100%; margin-left:auto; margin-right:auto; background-color:black; background-position:center;overflow:hidden">
    <div style="height:6px;"></div>
    
    <div id="heading" style=
    "font-family:'times roman', arial, verdana; font-size:1.5em; width:886px; height:50px; border-style:solid; background-position:center; margin-left:auto; margin-right:auto; border-color:gray; border-width:1px; background-color:#262626; color:yellow; filter:alpha; opacity:60%; font-weight:normal; text-align:center; margin-bottom:10px; x; text-decoration:underline; padding-top:8px;">
    Andrew's CSS Test Page
    </div>
    
    <div id="left-column" style=
    "width:125px; float:left; margin-left:14px; border: 1px solid red;overflow:hidden">
    <div id="menu" style=
    "width:125px; /*height:267px;*/ background-color:fuchsia; filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC; border-width:1px;">
    Content
    
    <div style=
    "width:125px; height:96px; background-color:black; filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC; border-width:1px; margin-top:10px; padding-top:4px;">
    Content
    </div>
    
    <div style=
    "width:125px; height:96px; background-color:black; filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC; border-width:1px; margin-top:10px; padding-top:4px;">
    Content
    </div>
    
    <div style=
    "width:125px; height:96px; background-color:black; filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC; border-width:1px; margin-top:10px; padding-top:4px;">
    Content
    </div>
    </div>
    </div>
    
    <div id="middle-column" style=
    "width:700; margin-left:10px; margin-bottom:0px; float:left;text-align:left;">
    <div style=
    "width:590px; background-color:black; color:white; filter:alpha; opacity:0.8; border-style:inset; border-color:#CCCCCC; border-width:1px; padding: 5px; line-height:25px;">
    Content
    </div>
    
    <div style="width:200px; height:200px; background-color:white;"></div>
    </div>
    </div>
    </body>
    </html>

    Comment

    • AJM Project
      New Member
      • Aug 2008
      • 10

      #3
      Hi,

      Sorry I'm quite new so bare with me. What do you mean by enclose the floats?

      It seems when I posted the code (as I took content out to keep it down) I accidently took out one of the closing divs (the menu one), otherwise, the divs are in the wrong order, how?

      Also, why have you put css quotes on the height attributes? I don't understand. Do I need them or not? and what actually fixed the problem?

      ps. All the right side of the borders of the divs in the left column have now dissapeared.

      Thank you for helping, I appreciate you taking the time to look through it. :D

      Comment

      • David Laakso
        Recognized Expert Contributor
        • Aug 2008
        • 397

        #4
        If this valid online page [1] is not what you are looking for, then I misunderstood the question(s) and someone else will help you out.

        [1] http://www.chelseacree kstudio.com/ca/cssd/test-30.html

        overflow: hidden; was used on several containers to clear (enclose) the floats.
        The goofy colors and borders were used to see if the floats were indeed cleared-- and so we both could see the selectors targeted.

        Your columns were out of order because you opened the right column before you closed the sidebar.

        I don't have time to list the other changes -- that's why I provided the file -- I sort of hoped you would compare my file with yours to see exactly what changed. Use the above online file for comparison.

        Comment

        • AJM Project
          New Member
          • Aug 2008
          • 10

          #5
          Hello,

          I did look and see what was changed. And as I said the closing div not being there was a mistake. I know what overflow does but as I am still pretty new to CSS I hadn't heard the term enclose before when relating to this.

          You fixed my problem but what I just asked you was were the height attributes that you highlighted required? ie. why were they highlighted?

          Basically to enable the container div to expand all the way in the future, I need to make the height attribute 100% and make sure all floated divs are enclosed?

          Thanks

          Comment

          • David Laakso
            Recognized Expert Contributor
            • Aug 2008
            • 397

            #6
            Originally posted by AJM Project

            ...but what I just asked you was were the height attributes that you highlighted required? ie. why were they highlighted?

            Highlighted? I deleted them if that's what you mean?

            Basically to enable the container div to expand all the way in the future, I need to make the height attribute 100% and make sure all floated divs are enclosed?
            Yes the floats need to be cleared.
            Normally height is not set on content bearing containers. It's ok in your little demo. But in a real world page, the height of the container(s) is determined by the amount of content. Put enough content in any container and it could expand vertically, even with text-scaling employed, from here to the Equator (if not further) without breaking out the bottom.

            Most stuff will be a lot clearer for you if you embed all the styles in the head of the document. Put real content or "lorum ipsum" set at default in the containers And check the page in IE/6, IE/7 at text-size "largest"; and at least +2 font-scaling in a pre 3.0 Firefox browser, Safari, and Camino-- and with font zoom in Opera. The floats should not drop, and the text should not shoot out the bottom of any container. Coping with long words breaking out horizontally from narrow containers is yet another matter...

            Comment

            • AJM Project
              New Member
              • Aug 2008
              • 10

              #7
              Excellent, I feel I understand a lot more now. Thank you David. :D

              Comment

              Working...