How do I make sure that my footer shows all the way at end of the page rather than in the middle?

前端 未结 2 1274
别跟我提以往
别跟我提以往 2021-01-07 11:25

Here\'s my footer css:

 .footer {
      background-color: #CACACA;
      font-size: 20px;
      height: 50px;
      padding-top: 10px;
      position: absol         


        
相关标签:
2条回答
  • 2021-01-07 11:33

    Without seeing the corresponding HTML, it's a bit hard to guess what your issues might be. It sounds like there's a bottom margin on your main content that's pushing the page bottom downward past the footer when there's only limited content inside that main section.

    To fix it, either adjust that margin or else change the positioning of the footer. At the moment, the position is absolute, which means that the footer is positioned based upon the its parent element in the HTML. Switching the positioning to relative will make it appear just after whatever element comes just before it in the HTML.

    I suggest you read more about CSS positioning before trying to work on the issue further.

    0 讨论(0)
  • 2021-01-07 11:54

    like so

      <!DOCTYPE html>
    <html>
    <head>
        <title>My Amazing Footer</title>
        <style>
        html, body {
           margin:0;
           padding:0;
           height:100%;
        }
        .wrapper {
           min-height:100%;
           position:relative;
        }
        footer{
            background:#F1F1F1;
            position: absolute;
            bottom: 0px;
            left: 0px;
            width: 100%;
            height:300px;
        }
    
        footer p{
            text-align: center;
            padding-top:100px;
        }
        </style>
    </head>
    <body>
        <div class="wrapper">
            <div class="Content">
                <p>HTML Ipsum Presents</p>
            </div>
            <footer>
                <p>&copy; My Website 2013. All Rights Reserved!</p>
            </footer>
    
        </div>
    </body>
    </html>
    

    see we have the footer in the wrapper and the footer is absolute to the bottom and left of the wrapper then we just add the height of the footer to the wrapper bottom padding and some default height on the wrapper and body and that's sorted, take a look on jsfiddle here - http://jsfiddle.net/eTwJh/2/ and here is one with no content - http://jsfiddle.net/eTwJh/3/

    0 讨论(0)
提交回复
热议问题