Results 1 to 7 of 7

Thread: Height

  1. #1
    CimminyCricket's Avatar
    Join Date
    May 2006
    Posts
    4,911

    FFXIV Character

    Caedus Ulvein (Sargatanas)

    Default Height

    I use CSS/HTML Div to create a container that holds all the information on my website. Thing is, for some reason I can't set the height of that container to 100%. If I set it, it completely closes on all the content on that page, however large, and the content then falls outside of the container and into the background. How do I fix this? I have to separate style sheets, one for pages with little content, and then one for pages with tons. How can I get the ideal height: 100%; to work? Does it work at all?


  2. #2
    i n v i s i b l e Tech Admin o_O's Avatar
    Join Date
    Jun 2001
    Location
    New Zealand
    Posts
    2,957
    Blog Entries
    1

    FFXIV Character

    Humphrey Squibbles (Sargatanas)

    Default

    The height property of block elements (<div> is our block in this case) only works with a percentage if its parent element has a height attribute to which it can scale. Basically, it means that you need whatever elements the div sits inside to all have the style "height: 100%;" right up to the top level.

    Then you can simply assign the height of the document to be 100% and your divs should fill up whatever space is there:
    PHP Code:
    <!-- Not actually PHP :-->
    <
    html>
      <
    head>
        &
    lt;style type="text/css">
          
    html body height100%; }
          
    body background-colorblack; }
          .
    fullHeight height100%; }
          .
    lolClass background-colorblue; }
          
    /* other styles here */
        
    </style>
      </
    head>

      <
    body>
        <
    div class="fullHeight"> <!-- Outer div -->
          <
    div class="fullHeight lolClass"> <!-- Inner div -->
            <
    center>This div should take up the full height of the page.</center>
          </
    div>
        </
    div>
      </
    body>
    </
    html
    You can see that the blue background of the inner div takes up the full height of the outer div, which in turn takes up the full height of the page (or body, as defined in the CSS).

  3. #3
    CimminyCricket's Avatar
    Join Date
    May 2006
    Posts
    4,911

    FFXIV Character

    Caedus Ulvein (Sargatanas)

    Default

    I didn't understand the majority of that.

    I have 4 other div's in my container, main(center), menu(left), main_right(right), header (top), if I sent them, to 100% (main and header at least) and then give the left and right a specific height, will this fix the craziness?


  4. #4
    i n v i s i b l e Tech Admin o_O's Avatar
    Join Date
    Jun 2001
    Location
    New Zealand
    Posts
    2,957
    Blog Entries
    1

    FFXIV Character

    Humphrey Squibbles (Sargatanas)

    Default

    Basically you need to take note of your document structure. That is, the tags and elements which occur inside of other elements. For example:
    PHP Code:
    <html>
      <
    head> <!-- parent is <html> -->
        &
    lt;style>
          
    /* whatever style */
        
    </style>
      </
    head>

      <
    body> <!-- parent is also <html> -->
        <
    div>
            
    The parent of this <divis the <bodyelement, as it is inside the opening and closing tags of the body.
            <
    img src="whatever.gif" /> <!-- The parent of this <imgis the <divtag, as you can see it occurs after the div opensbut before it closes below. -->
        </
    div>
      </
    body>
    </
    html
    Hopefully you can see here that there's a hierarchy of elements:
    - html > head > style
    - html > body > div > img

    In order to give an element a height of 100%, you need to progress right back up the hierarchy to <html>. It'd be easier to illustrate if you post the code in question; then I could demonstrate on the code you actually want to use.

  5. #5
    CimminyCricket's Avatar
    Join Date
    May 2006
    Posts
    4,911

    FFXIV Character

    Caedus Ulvein (Sargatanas)

    Default

    PHP Code:
    <html>
    <
    head>
    </
    head>
    <
    body>
    <
    div id="container">
    <
    div id="header">Stuff</div>
    <
    div id="main_right">Something</div>
    <
    div id="menu_right">Some more things</div>
    <
    div id="main">
    <
    div id="padded">
    Some things heretoo.
    </
    div>
    </
    div>
    </
    div>
    </
    body>
    </
    html
    Code:
    #container {  
    	color: black;
    	background: white;
    	font-size: 1.2em;
            border-top: none;
    	margin-left: 100px;
            height: 2000px;
            height: 2150 !Important;
            width: 845px !Important;
            width: 840px;
            margin-left: 48px !important;
            margin-right: 140px; 
            margin-top: -10px;
            text-align: center;
            padding-bottom: -10px;
            padding-bottom: 0px !important;
    }
    
    div#main {
    	width: 410;
            background: none;
            color: black;
            height: 1440px !important;
            height: 1430px;
            
            text-align: left;
            padding-left: 110px !Important;
            padding-left: 0px;
            padding-top: 30px;
            margin-left: 90px !Important;
    }
    div#main_right {
    	float: right;
    	width: 150px;
    	color: black;
            background-image: url('RoundedMenu2.png');
            height: 1600px;
            height: 1950px !Important;
            margin-right: 0px !important;
            margin-right: -10px;
            
                   
            
    }
    div#menu_right {
    	float: left;
    	width: 150px;
    	background-image: url('RoundedMenu1.png');
            height: 1600px;
            height: 1950px !Important;
            text-align: left;
    	      
    }
    div#header {
    	width: 850px;
    	background: none;
    	font: normal 2.4em Verdana,sans-serif;
    	line-height: 10px;
    	text-align: right;
    	height: 200px;
            margin-right: 0px !Important;
            margin-right: -5px;
    }


  6. #6
    i n v i s i b l e Tech Admin o_O's Avatar
    Join Date
    Jun 2001
    Location
    New Zealand
    Posts
    2,957
    Blog Entries
    1

    FFXIV Character

    Humphrey Squibbles (Sargatanas)

    Default

    Quote Originally Posted by Cim View Post
    PHP Code:
    <html>
    <
    head>
    </
    head>
    <
    body>
    <
    div id="container">
    <
    div id="header">Stuff</div>
    <
    div id="main_right">Something</div>
    <
    div id="menu_right">Some more things</div>
    <
    div id="main">
    <
    div id="padded">
    Some things heretoo.
    </
    div>
    </
    div>
    </
    div>
    </
    body>
    </
    html
    Code:
    html > body { height: 100%; }
    
    #container {  
    	color: black;
    	background: white;
    	font-size: 1.2em;
            border-top: none;
    	margin-left: 100px;
            height: 100%;
            height: 2150 !Important;
            width: 845px !Important;
            width: 840px;
            margin-left: 48px !important;
            margin-right: 140px; 
            margin-top: -10px;
            text-align: center;
            padding-bottom: -10px;
            padding-bottom: 0px !important;
    }
    
    div#main {
    	width: 410;
            background: none;
            color: black;
            height: 1440px !important;
            height: 1430px;
            
            text-align: left;
            padding-left: 110px !Important;
            padding-left: 0px;
            padding-top: 30px;
            margin-left: 90px !Important;
    }
    div#main_right {
    	float: right;
    	width: 150px;
    	color: black;
            background-image: url('RoundedMenu2.png');
            height: 1600px;
            height: 1950px !Important;
            margin-right: 0px !important;
            margin-right: -10px;
            
                   
            
    }
    div#menu_right {
    	float: left;
    	width: 150px;
    	background-image: url('RoundedMenu1.png');
            height: 1600px;
            height: 1950px !Important;
            text-align: left;
    	      
    }
    div#header {
    	width: 850px;
    	background: none;
    	font: normal 2.4em Verdana,sans-serif;
    	line-height: 10px;
    	text-align: right;
    	height: 200px;
            margin-right: 0px !Important;
            margin-right: -5px;
    }
    Here you go. You only need two changes, the height of your container should be 100% and you need the body height declaration, both of which I added above.

  7. #7
    CimminyCricket's Avatar
    Join Date
    May 2006
    Posts
    4,911

    FFXIV Character

    Caedus Ulvein (Sargatanas)

    Default

    Totally awesome, o_O.

    If you were an item, I bet I could equip you for +100 to Internet.


Posting Permissions

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