Footer goes up whenever i open Chrome Console

对着背影说爱祢 提交于 2019-12-11 00:50:24

问题


So, I admit I'm not that good at CSS, and this might be something dumb on my end, but I want to have a sticky footer at the bottom of every page on my site.

I'm using a position absolute this is the CSS for my footer

    position:absolute;
    bottom:0;
    height:50px;
    padding: 10px;
    width:100%;

It works when the console is closed, but if I open the Chrome Developer tools, the footer suddenly goes up as if it were fixed to the browser window which is not the case.

Am I doing anything wrong?

How do others do sticky footers?

EDIT

I've created a simple codepen with an example of the issue

http://codepen.io/anon/pen/yMLBdJ

Open the dev tools below the footer and you'll notice the footer is still visible, shouldn't it be invisible behind the dev tools? That's the questions. sorry ahead of time if it's a dumb one.


回答1:


Since you know the height of your footer you could try:

html, body {
    height: 100%;
}

// wrapper around all content
main {
    min-height: 100%;
}

main::after {
    content: '';
    display: block;
    height: 70px; // height + padding
}

footer {
    background: grey;
    margin-top: -70px;
    padding: 10px;
    height: 50px;
    width: 100%;
}

With this the footer is at the bottom unless the content exceeds the window height. If you want the footer to be fixed to window just add:

position: fixed;
bottom: 0;

CodePen: http://codepen.io/MusikAnimal/pen/OpLeEM




回答2:


In case of position: absolute The element is positioned relative to its first positioned (not static) ancestor element.

If you want to make it stick to the window, use position:fixed

You can play around with it here

And for your sticky footer, you should refer to this nice article



来源:https://stackoverflow.com/questions/42407915/footer-goes-up-whenever-i-open-chrome-console

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