仅对 HTML 内容显示垂直滚动条

发布于 2024-11-07 15:13:07 字数 4207 浏览 0 评论 0原文

我有一个 HTML 标记,顶部有固定头,底部有脚。 Foot 不是固定的,但始终位于视口的底部,如果浏览器调整高度,它应该位于内容的正下方。在这种情况下,应该出现一个垂直滚动条。滚动条应从头部下方开始,到窗口底部结束。 我有以下标记和 CSS:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>Scroll Test</title>
    <style type="text/css">
    html, body, #header
    {
        top: 0;
        right: 0;
        left: 0;
        bottom: 0;
    }
    html, body
    {
        min-height: 100%;
        width: 100%;
    }
    body { 
        overflow-y:hidden;
        margin:0;
        position: absolute;
        padding: 0;
    }
    #header
    {
        position: fixed;
        height: 120px;
        z-index: 9200;
        background: #555;
        min-width: 945px;
    }
    .page_margins_scroller
    {
        height: 100%;
        overflow-y:auto;
    }
    .page_margins
    {
        min-width: 945px;
        min-height: 100%;
        background: #888;
    }
    .page
    {
        padding-top: 120px;
    }
    #footer
    {
        background: #ccc;
    }
    </style>
  </head>
  <body>
    <div id="header">
        Head
    </div>
    <div class="page_margins_scroller">
        <div class="page_margins">
            <div class="page">
                <div id="main">
                Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. 

                Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 

                Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 

                Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. 
                </div>
            </div>
        </div>
        <div id="footer">
            Foot
        </div>
    </div>
  </body>
</html>

这段代码存在问题,我向您寻求解决方案:

  • 滚动条位于头部后面 滚动条
  • 始终可见并滚动一点(可能是因为内容的 100% 的高度
  • 如果我将浏览器的宽度调整到 945px 以下并向左滚动,脚的宽度不是 100%(背景颜色为白色)[编辑] 对于这个问题,我们必须添加 min-width: 945px ; to #footer [/edit]
  • 它在 IE7 中不起作用

我已经在 IE7、IE8、IE9 和 FF4 上进行了测试,我想让它在所有这些浏览器中运行,也许在 FF3.6 中 可以更改标记。

也许有人有一个简单的解决方案,希望不需要 JavaScript,如果您愿意, 约亨

I have a HTML Markup with a fixed head at the top and a foot at the bottom. The Foot is not fixed, but always at the bottom of the viewport and it should be directly below the content if the browser is resized in height. In this case a vertical scrollbar should appear. The scrollbar should start below the head and end at the bottom of the window.
I have the following markup and CSS:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>Scroll Test</title>
    <style type="text/css">
    html, body, #header
    {
        top: 0;
        right: 0;
        left: 0;
        bottom: 0;
    }
    html, body
    {
        min-height: 100%;
        width: 100%;
    }
    body { 
        overflow-y:hidden;
        margin:0;
        position: absolute;
        padding: 0;
    }
    #header
    {
        position: fixed;
        height: 120px;
        z-index: 9200;
        background: #555;
        min-width: 945px;
    }
    .page_margins_scroller
    {
        height: 100%;
        overflow-y:auto;
    }
    .page_margins
    {
        min-width: 945px;
        min-height: 100%;
        background: #888;
    }
    .page
    {
        padding-top: 120px;
    }
    #footer
    {
        background: #ccc;
    }
    </style>
  </head>
  <body>
    <div id="header">
        Head
    </div>
    <div class="page_margins_scroller">
        <div class="page_margins">
            <div class="page">
                <div id="main">
                Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. 

                Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 

                Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. 

                Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. 
                </div>
            </div>
        </div>
        <div id="footer">
            Foot
        </div>
    </div>
  </body>
</html>

Problems I have with this code, and I ask you for solutions:

  • The scrollbar is behind the head
  • The scrollbar is always visible and scrolls a little bit (maybe because of the height of 100% of the content
  • if I resize the browser below 945px in width and scroll left the width of the foot is not 100% (background color is white) [edit] OK for this problem we have to add min-width: 945px; to #footer [/edit]
  • It doesn't work in IE7

I have tested with IE7, IE8, IE9 and FF4 and I want to make it work in all of them, maybe in FF3.6 too. Maybe somebody has a simple solution, hopefully without JavaScript. If you want you can change the markup.

Thanks in advance
Jochen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

未蓝澄海的烟 2024-11-14 15:13:07

看看这个小提琴:http://jsfiddle.net/anish/Rs982/

我没有检查IE 下的,请检查一下。

check out this fiddle:http://jsfiddle.net/anish/Rs982/

i didn't check it in IE.please check it.

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