Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with absolute positioning footer

    I cannot get the footer to sit at the bottom of the page when I use absolute positioning. I need the #main to stretch to whatever the content height and the footer to sit underneath. Can anyone help?


    html, body {height:100%;}

    #container {
    width: 900px;
    position: absolute;
    top: 0px;
    left: 50%;
    margin-left: -450px;
    }

    #header {
    width: 900px;
    height: 105px;
    position: absolute;
    left:0;
    top: 0;
    }

    #main {
    position: absolute;
    left:0;
    top: 105px;
    }

    #footer {
    position:absolute;
    bottom:0;
    border: 1px solid yellow;
    }

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,748
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    Hello tempest4000,
    There's no real need for absolute positioning in your layout, not yet anyway. Have a look at the pitfalls of absolute positioning.

    Here it is just flowing naturally instead of using ap -
    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>Untitled Document</title>
    <style type="text/css">
    html, body {
    	height:100%;
    	font: 100.1% "Comic Sans MS";
    	background: #FC6;
    }
    * {
    	margin: 0;
    	padding: 0;
    	border: 0;
    	outline: 0;
    }
    #container {
    	width: 900px;
    	margin: 30px auto 0; /*centers and moves #container down 30px*/
    	background: #999;
    	font-size: 0.8em;
    } 
    #header {
    	height: 105px;
    	background: #0F0; /*just for testing*/
    }
    #main {background: #ccc;}
    #footer {
    	height: 105px;
    	border: 1px solid yellow; 
    } 
    </style>
    </head>
    <body>
        <div id="container">
            <div id="header">
                header
            </div>
        <div id="main">
                <p>
                    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna 
                    aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no 
                    sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam 
                    nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo 
                    duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
                </p>
                <p>
                    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna 
                    aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no 
                    sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam 
                    nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo 
                    duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
                </p>
        <!--end main--></div>
            <div id="footer">
                footer
            </div>
        <!--end container--></div>
    </body>
    </html>
    If you're looking for a full-height layout you will not get satisfactory results from an absolute positioned footer. Here is a demo of a very good solution http://nopeople.com/CSS/full-height-layout/index.html
    View the source to see how it's coded.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks but I had my website site up like that originally until I realised I needed absolute positioning for quite a few elements. The css gets quite complicated and what I have posted is just the main structure.

    Does anyone know of any way I can get this to work?

  • #4
    New Coder
    Join Date
    Jul 2009
    Location
    Bristol, England
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Lightbulb

    I recently had a similar problem, although I wasn't using absolute positioning... but this may work for you... I tried to find the article where I found it, but it seems to have disappeared!!

    I had a three column layout, and I wanted to stretch the menu column to the same height as the content, and then the footer to sit underneath... which sounds like the same problem you're having...

    I put this into the CSS for the menu:

    Code:
    padding-bottom:2000px;
    margin-bottom:-2000px;
    this in the CSS for the footer:

    Code:
    clear:both;
    and this in the CSS for the container:

    Code:
    overflow:hidden;
    It's a bit of a messy solution, but it works in all the browsers I've tested it in. Let me know if that helps

  • #5
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,748
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    If you're looking for a full-height layout you will not get satisfactory results from an absolute positioned footer. Here is a demo of a very good solution http://nopeople.com/CSS/full-height-layout/index.html
    View the source to see how it's coded.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Posting Permissions

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