removing page scrollbars in IE8 (overflow:hidden n

2019-01-25 22:03发布

问题:

Applying this

overflow:hidden;

to the body of my document has no effect in IE8. Any ideas why?

回答1:

It depends on whether IE8 is rendering the page in Standards or Quirks mode. For example, the following HTML will be displayed without a scrollbar:

<!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" xml:lang="en-US" lang="en-US">
    <head>
        <title>test</title>
    </head>
    <body>
        <p>hello</p>
    </body>
</html>

But if you remove the doctype declaration, IE8 renders the page in Quirks mode:

<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <p>hello</p>
    </body>
</html>

You can also check this by forcing the rendering mode with the Developer Tools. Press F12 on a page, and at the end of the menu bar (for some reason...) there's a "Document Mode" setting. Toggling between Standards and Quirks here should also toggle the scrollbar.

So... you need to make your page adhere to an HTML standard! It need not be XHTML Strict, it could be HTML 4, or even XHTML Transitional if you really must.

The W3C Validator can help you with any validation errors.



回答2:

It must be something else, because I just applied overflow:hidden on this stackoverflow page's HTML element and the scrollbar disappeared.

Could you post some more css or code?

Edit: I also tried it on the body element and it also worked.. no more scrollbar.



回答3:

add this IE hack:

 max-height: none\9