页脚位于视口底部,不与内容重叠
我需要的是一个非常基本的布局,只有两个主要部分:内容和页脚。 页脚应始终位于视口的底部。 所以我有:
- 内容(位置:相对)
- 页脚(位置:固定;底部:0px) 当我的内容很少时,这很有效(请参阅图片 1)。
当视口太短或有大量内容时,问题就会出现(请参阅图片 2)。
内容位于页脚后面(重叠),并且出现页面滚动。
我也不想让它走在前面。 我想要的是这样的(参见图片3)
内容不与页脚重叠,并且页面滚动仅滚动内容 div。
我不知道如何实现这一点,也不知道是否可以做到。 我不介意使用jquery,也不关心ie6。 任何帮助将不胜感激
谢谢
编辑:
感谢您的回复。
我正在上传几张图片,以便您可以更好地了解我需要什么。
在图像 1 http://estudioibarra.com/test/image1.jpg 中,您可以看到设计我想要,在图像 2 http://estudioibarra.com/test/image2.jpg 中同一张图片,带有一些解释。
我想要的是标题始终位于视口底部,因为这是我的菜单。我不希望内容与我的菜单重叠。因为内容会有超过3个项目。
我不想要的是这个 http://estudioibarra.com/test/image3.jpg (内容出现在菜单后面)。
通过你的一些解决方案,我可以解决这个问题,但前提是我在容器 div 中有一个滚动条。我真的不喜欢这样。
有没有使用主页面滚动来滚动容器内容?
再次感谢您的宝贵时间
What I need is a very basic layout with only 2 main parts: content and footer.
The footer should always be on bottom of viewport.
So I have:
- Content (position:relative)
- Footer (position: fixed; bottom:0px)
That works grate when I have few content (see image 1).
The problem starts when the viewport is too short or have lots of content (see image 2).
The content goes behind the footer (overlaping) and the page scroll appears.
I don't want it to go in front either.
What I would like is this (see image 3)
The content doesn't overlap with the footer, and the page scroll only scroll the content div.
I don't know how to accomplish that or even if it can be done.
I don't mind using jquery and I don't care for ie6.
Any help would be very appreciated
Thanks
EDIT:
Thanks for the reply's.
I'm uploading a couple of images so you can better understand what I need.
In image 1 http://estudioibarra.com/test/image1.jpg you can see the design I want, and in Image 2 http://estudioibarra.com/test/image2.jpg is the same image with some explanations.
What I want is the header always on bottom of viewport because is my menu. And I don't want the content to overlap with my menu. because the content will have more than 3 projects.
What I don't want is this http://estudioibarra.com/test/image3.jpg (content appearing behind menu).
With some of your solutions I can solve that, but only if I have a scroll in the container div. I really don't like that.
Is there to use the main page scroll to scroll the container content??
Thanks again for your time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如何简单地将内容和页脚设置为
position:fixed
并将它们放置在您想要的位置,就像这个演示一样:http://jsfiddle.net/bAtVE/?编辑:
我这次使用了
position:absolute
(参见http ://jsfiddle.net/bAtVE/1/)。这可能是一个更好的做法,因为固定位置不那么跨浏览器兼容。编辑2:
http://jsfiddle.net/bAtVE/2/
How about simply making both content and footer
position: fixed
and place them however you want, like this demo: http://jsfiddle.net/bAtVE/?EDIT:
I used
position: absolute
this time (see http://jsfiddle.net/bAtVE/1/). It is probably a better practice, asfixed
position is not as cross-browser compatible.EDIT2:
http://jsfiddle.net/bAtVE/2/
在下面的示例中,即使父元素中的内容溢出,页脚也将保持固定。容器尺寸可以是动态的,页脚宽度也会相应调整。页脚依赖于容器而不是浏览器窗口,这与
position:fixed
不同。使用 jQuery,您可以执行以下操作:在 http://jsfiddle.net/M2n8Q/ 查看工作示例
In the example below footer will remain fixed even if you have an overflow of content in the parent element. Container dimensions can be dynamic and footer width will adjust accordingly. Footer is dependent on the container and not browser window unlike
position:fixed
. With jQuery you can do:Check working example at http://jsfiddle.net/M2n8Q/
将页脚固定到底部并为其设置与背景颜色相同的
border-top
怎么样?演示: jsfiddle.net/Marcel/xgafM
What about just fixing the footer to the bottom and giving it a
border-top
the same color as the background?Demo: jsfiddle.net/Marcel/xgafM