仅对 HTML 内容显示垂直滚动条
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个小提琴: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.