CSS Layout How to - Create footer with position fixed








Question

We would like to know how to create footer with position fixed.

Answer


<html>
    <head>
        <style>
            #header{<!--from  w w  w  .j a  v a  2s. c  o m-->
                position:fixed;
                top:0;
                height:50px;
                z-index:5;
                width:100%;
            }
            #content{
                margin: 50px 0;
                width:100%;
            }
            #footer{
                position:fixed;
                background:#EEE;
                bottom:0;
                height:50px;
                z-index:5;
                width:100%;
            }
        </style>
    </head>
    <body>
        <div id="header" > <h1>This is header</h1> </div>
        <div id="content" >
            <p>alot of content</p>
        </div>
        <div id="footer" > <h1>This is footer</h1> </div>
    </body>
</html>

The code above is rendered as follows: