页脚位于视口底部,不与内容重叠

发布于 2024-10-27 04:03:01 字数 1213 浏览 8 评论 0原文

我需要的是一个非常基本的布局,只有两个主要部分:内容和页脚。 页脚应始终位于视口的底部。 所以我有:

  • 内容(位置:相对)
  • 页脚(位置:固定;底部: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦罢 2024-11-03 04:03:01

如何简单地将内容和页脚设置为 position:fixed 并将它们放置在您想要的位置,就像这个演示一样:http://jsfiddle.net/bAtVE/

#content {
    position: fixed;
    height: 85%;
    width: 95%;
    border: 1px blue solid;
    overflow-y: auto;
}

#footer {
    position: fixed;
    height: 10%;
    width: 95%;
    bottom: 0;
    border: 1px red solid;
}

<div id="content">
    here is content
</div>
<div id="footer">
    This is footer
</div>

编辑

我这次使用了position:absolute(参见http ://jsfiddle.net/bAtVE/1/)。这可能是一个更好的做法,因为固定位置不那么跨浏览器兼容。

#content {
    position: absolute;
    top: 0;
    left: 0;
    height: 85%;
    width: 100%;
    overflow-y: auto;
}

#footer {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 10%;
    width: 100%;
}

编辑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/?

#content {
    position: fixed;
    height: 85%;
    width: 95%;
    border: 1px blue solid;
    overflow-y: auto;
}

#footer {
    position: fixed;
    height: 10%;
    width: 95%;
    bottom: 0;
    border: 1px red solid;
}

<div id="content">
    here is content
</div>
<div id="footer">
    This is footer
</div>

EDIT:

I used position: absolute this time (see http://jsfiddle.net/bAtVE/1/). It is probably a better practice, as fixed position is not as cross-browser compatible.

#content {
    position: absolute;
    top: 0;
    left: 0;
    height: 85%;
    width: 100%;
    overflow-y: auto;
}

#footer {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 10%;
    width: 100%;
}

EDIT2:

http://jsfiddle.net/bAtVE/2/

南巷近海 2024-11-03 04:03:01

在下面的示例中,即使父元素中的内容溢出,页脚也将保持固定。容器尺寸可以是动态的,页脚宽度也会相应调整。页脚依赖于容器而不是浏览器窗口,这与 position:fixed 不同。使用 jQuery,您可以执行以下操作:

var cw = $('#container').innerWidth();

$('#header').css({
    'width': cw + "px"
});

$('#container').scroll(function() {
    $('#header').css({
        'bottom': -$('#container').scrollTop()
    })
})

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:

var cw = $('#container').innerWidth();

$('#header').css({
    'width': cw + "px"
});

$('#container').scroll(function() {
    $('#header').css({
        'bottom': -$('#container').scrollTop()
    })
})

Check working example at http://jsfiddle.net/M2n8Q/

隔岸观火 2024-11-03 04:03:01

将页脚固定到底部并为其设置与背景颜色相同的 border-top 怎么样?

body { background:#eeeeed; }
#wrap { width:34em; margin:0 auto; }
#head, #foot { padding:1em 2em; }
#head, #main { background:#fff; }
#main { padding:0 2em 6em; }
#foot {
    bottom:0;
    color:#fff;
    width:30em;
    position:fixed;
    background:#444;
    text-align:center;
    border-top:1em solid #eeeeed;
}

演示: 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?

body { background:#eeeeed; }
#wrap { width:34em; margin:0 auto; }
#head, #foot { padding:1em 2em; }
#head, #main { background:#fff; }
#main { padding:0 2em 6em; }
#foot {
    bottom:0;
    color:#fff;
    width:30em;
    position:fixed;
    background:#444;
    text-align:center;
    border-top:1em solid #eeeeed;
}

Demo: jsfiddle.net/Marcel/xgafM

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文