www.webdeveloper.com
Results 1 to 4 of 4

Thread: fluid-height div between two fixed-height fixed-position divs

  1. #1
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264

    Exclamation fluid-height div between two fixed-height fixed-position divs

    I have a header and footer that are specific (pixel) heights and position:fixed.

    I have a content box between them that needs to resize based on the window height... On my monitor "74%" is perfect, but on my second monitor it's more like "85%"... My header is 110px tall and my footer is 60px tall... How do I make the content stay between them?

    I currently have the content as position:absolute and with margins on the top and bottom of the right sizes, but it doesn't really work because the "height: 74%;" doesn't change based on the screen size and the header and footer sizes don't change at all...

    Any help on this would be greatly appreciated.

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    Fixed and absolute positioning, hummm!
    Did you choose the fixed positioning because you don't want the header and footer to move when the page is scrolled or do you have other reasons?

  3. #3
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    Yes, that's exactly why. The header and footer are transparent (backgrounds) and there is a background image for the whole page... so content showing up behind the header (logo & Navigation) or footer (copyright info) looks horrible.

  4. #4
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    Unless you don't want the content area's height to stretch as needed, you will have the same issue as the content grows.
    Because of the difference in screen sizes the percentage in the height will not work the same for all users.

    Try this:

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Test page</title>
    <style>
    html{
    height: 100&#37;;
    }
    body{
    margin:0;
    padding:0;
    background:#000;
    height: 100%;
    }

    #header{
    position:fixed;
    width:100%;
    height:110px;
    margin:0;
    padding:0;
    left:0;
    top:0;
    background:#666;
    z-index:100;
    }

    #maincontent{
    width:100%;
    height:100%;
    margin:0;
    padding:110px 0 60px;
    box-sizing:border-box;
    -moz-box-sizing:border-box;
    -webkit-box-sizing:border-box;
    position:relative;
    z-index:1;
    }


    #content{
    width:100%;
    height:100%;
    margin:0;
    padding:0;
    background:#fff;
    position:relative;
    }

    #footer{
    position: fixed;
    height: 60px;
    margin: 0;
    padding: 0;
    left: 0;
    bottom: 0;
    background: #666;
    width: 100%;
    z-index:100;
    }

    </style>
    </head>
    <body>
    <div id="header">&nbsp;</div>
    <div id="maincontent">
    <div id="content">content area
    </div>
    </div>
    <div id="footer">&nbsp;</div>
    </body>
    </html>
    Last edited by holyhttp; 05-31-2012 at 03:32 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles