CSS 页脚定位问题
这是我迄今为止所拥有的内容的预览:
红色区域是设计的一部分,应始终随设计一起向下滚动。因此,当内容扩展时,页脚和红色栏也会随之扩展。它应该位于窗口的最底部。
我尝试将其绝对定位并且它工作得很好,除了当我重新调整浏览器大小并将其缩小时,它会停留在最底部,但仅在浏览器全屏时才工作。
我现在所做的只是将其相对于 top:-120px; 定位然后如您所见,它给了我想要摆脱的额外空白。
footer { height:185px; background:url(../images/footer_bg.png) repeat-x; position:relative; z-index: 0; top:-115px; width:100%; }
不知道还要粘贴什么代码,我认为这就是每个人都需要的。其余的都是不言自明的。有人对如何解决这个问题有任何建议吗?
我的目标是让它像上图一样,除了没有空白之外,即使在调整浏览器大小时,也始终将其推到底部。
Here is a preview of what I have so far:
The red area is part of the design and should always scroll down with the design. So when the content expands, the footer, and that red bar go with it. This should be at the very bottom of the window.
I tried positioning it absolute and it worked perfectly, except when I re-sized my browser and made it smaller, it would stay at the very bottom but would only work when the browser is in full screen.
What I am doing right now is just positioning it relative with top:-120px; and then as you can see, it gives me the extra whitespace that I want to get rid of.
footer { height:185px; background:url(../images/footer_bg.png) repeat-x; position:relative; z-index: 0; top:-115px; width:100%; }
Not sure what else code to paste, I think that's all everyone needs. The rest is self explanatory. Does anyone have any suggestions on how to approach this?
My goal is to get it just like the image above except without the whitespace, pushed down at the bottom at all times, even when the browser is re-sized.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们也使用粘性页脚 - 这是基础知识:
注意容器末尾之前的清除页脚。然后使用CSS,你需要这样的东西:
唯一的缺点是这是一个固定高度的页脚。也不要忘记,如果您向页脚添加任何填充以增加高度,并且页脚、clearfooter 和容器上的负边距的高度需要相应调整。
如果您碰巧需要它在 IE6 中工作,您需要以您想要的方式定位容器并使用:
希望有帮助!
we use a sticky footer as well - here's the basics:
Note the clearfooter before the end of the container. Then with CSS you need something like this:
The only downside is that this is a fixed height footer. Don't forget, too if you add any padding to your footer that increases the height and your height on the footer, clearfooter and negative margin on the container need to be adjusted accordingly.
If you happen to need it to work in IE6 you'll need to target the container however you'd like and use:
Hope that helps!
粘性页脚可能会很棘手,而添加重叠的背景可能会更棘手。您可能想要尝试的是创建一个 粘性页脚 并将背景图像应用到主体或容器背景上,重复 - x 和位置底部。
你能创建一个jsfiddle吗,我可以向你展示我所说的技术。
Sticky footers can be tricky and adding an over lapping background can be even more tircky. What you might want to try is creating a Sticky footer and applying the background image to the body or container background repeating-x and position bottom.
Are you able to create a jsfiddle and I can show you the technique I mean.
当您使用
position:relative
偏移某些内容时,该元素仍然“保留”它本来占据的空间 - 在您的情况下,即获得空白的底部区域。在页脚上设置margin-bottom: -115px
以告诉它不要这样做。When you are offsetting something with
position: relative
, the element still "reserves" the space it would have occupied otherwise - in your case, the bottom area where you get the whitespace. Setmargin-bottom: -115px
on your footer to tell it not to do that.