开发者

Show vertical scrollbar only for HTML content

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;
    开发者_JS百科    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


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜