Results 1 to 6 of 6

Thread: Adding/subtracting dimensions?

  1. #1
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Adding/subtracting dimensions?

    Suppose I make a web with a header 100 pixels high, and I want the content of the page to fill the rest of the window; ie I have the following:

    Code:
    <html>
    <head>
    <style type="text/css">
    
    .header
    {
         width: 100&#37;;
         height: 100px;
    }
    
    .content
    {
         width: 100%;
         overflow: auto;
    }
    </style>
    </head>
    <body>
    
    <div class="header">
    
    Header here
    
    </div>
    
    <div class="content">
    
    Content here
    
    </div>
    </body>
    </html>
    Now, I want the content to be 100 pixels less than the full height of the window. Is there a way to do that without using javascript?

    Setting the height to 100% doesn't work; that makes the div extend 100 pixels beyond the bottom of the window.
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

  2. #2
    Join Date
    Nov 2006
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, the easy fix yet sort of difficult fix would to manually set a height...
    ie.
    Code:
    .content
    {
         width: 900px;
         overflow: auto;
    }
    That is just what I would do until I could find a more permanent fix... Sorry I couldn't be of more help.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's not a fix, since it won't work unless the window is exactly 1000px high.

    The best way to do it is to set height: 100&#37; and margin-top: 100px, I think, and apply overflow: hidden to the top of of the window, or a 100%&#215;100% container <div>.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, that worked wonders Twey. If anyone else is interested, this works:

    Code:
    <html>
    <head>
    <style type="text/css">
    
    body
    {
    	overflow: hidden;
    	padding: 0px;
    	margin: 200px 0px 0px 0px;
    }
    
    .header
    {
    	position: absolute;
    	top: 0px;
    	left: 0px;
    	width: 100&#37;;
    	height: 100px;
    }
    
    .content
    {
    	width: 100%;
    	height: 100%;
    	overflow: auto;
    }
    </style>
    </head>
    <body>
    
    <div class="header">
    
    Header here
    
    </div>
    
    <div class="content">
    
    Content here
    
    </div>
    </body>
    </html>
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Note that FireFox adds padding and margins when setting width to 100&#37;. So it may make the page scroll horizontally.
    - Mike

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Any design that depends on padding and margins should set them all to 0 by default anyway:
    Code:
    * {
      padding: 0;
      margin: 0;
    }
    ... since browser defaults differ.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •