CSS footer from cssstickyfooter.com not working correctly

隐身守侯 提交于 2019-12-11 12:03:59

问题


I got some simple CSS from http://www.cssstickyfooter.com/ to get a footer that always sticks no matter how long the content is. Now, this isn't actually working. I'm having two different problems with this footer, but I'm going to ask them both here because I suspect they're related.

First here's the css from the site:

html, body {height: 100%;}

#wrap {min-height: 100%;}

#main {overflow:auto;
    padding-bottom: 150px;}  /* must be same height as the footer */

#footer {position: relative;
    margin-top: -150px; /* negative value of footer height */
    height: 150px;
    clear:both;}

And here's the HTML I'm using for the whole page:

<html>
    <head>
        <title>{$title_text}</title>
        <link rel="stylesheet" type="text/css" href="/global/global.css" />
    </head>
    <body>
        <div id="wrap">
            {$navbar}<hr><div id="content">{$body}</div>
        </div>
        <div id="footer">
            {$footer}
        </div>
    </body>
</html>

As you can see, there are some variables formatted as {$variable}. These are pulled from another file/string.

Problem 1:

The footer is too high and overlaps with the other content on the page. Here's what that looks like:

To try to solve this problem, what I did was I added 200px of padding to the div of ID wrap, which is right before the footer (see HTML above). This will fix the problem you see in the picture there. But it causes another issue: now on pages with very little content, the footer is still moved down 200px, and you have to scroll down to see it. The site I got this CSS code from said this shouldn't happen.

Problem 2:

The footer doesn't reach the edges of the browser's window. Here's what I'm talking about:

The footer should be "touching" the right and left sides of the window, but as you can see, there seems to be a small margin. Honestly, I'm not sure how to start fixing this. But I don't think it's a bug because it renders the same way in Chrome, Firefox, and I think even in Internet Explorer.

Any input is welcome. Thanks for looking!


回答1:


Your html doesn't appear to match your css. Your css contains a '#main' but your main content appears in

<div id="content">...</div>



回答2:


1) Try change

#footer { position: relative; }

to #footer {position: absolute; }

2) Add to your code

html, body { padding: 0; margin: 0; } to prevent spaces around your footer



来源:https://stackoverflow.com/questions/10843522/css-footer-from-cssstickyfooter-com-not-working-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!