CSS:为什么html,body height: 100%大于100%?

发布于 2024-10-08 11:58:49 字数 887 浏览 0 评论 0原文

嘿,我试图做一个底部粘性页脚 链接测试,但它一直超过100%,这意味着它滚动了一点..

所以我做了一个简单的HTML代码,没有任何添加,但它仍然超过100%,请参见这里:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="he" lang="he" dir="rtl" id="bangler">
    <head>
        <title>my title</title>
        <style type="text/css">
        html, body, #wrapper { height: 100%; }
        body > #wrapper { height: auto; min-height: 100%; }
        </style>
    </head>
    <body>
        <div id="wrapper">aa</div>
    </body>
</html>

问题是,它滚动的幅度比 100% 多一点点,意味着多了 5-10 像素。这在 IE 和 Firefox 上都非常奇怪!

提前致谢 !

hey, i was trying to do a bottom sticky footer link test and but it kept being more then 100% meaning it scrolled a litle bit..

so i made a simple HTML code, without any additions but its still more than 100%, see here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="he" lang="he" dir="rtl" id="bangler">
    <head>
        <title>my title</title>
        <style type="text/css">
        html, body, #wrapper { height: 100%; }
        body > #wrapper { height: auto; min-height: 100%; }
        </style>
    </head>
    <body>
        <div id="wrapper">aa</div>
    </body>
</html>

the thing is, it scrolls just a little bit more then 100% meaning about 5-10px more.. this is really strange, on both IE and Firefox !!

Thanks in advance !

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

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

发布评论

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

评论(4

-柠檬树下少年和吉他 2024-10-15 11:58:49

这是因为默认的 body 边距。将其添加到您的样式中:

body { margin: 0; padding: 0; }

It's because of the default body margins. Add this to your styles:

body { margin: 0; padding: 0; }
许仙没带伞 2024-10-15 11:58:49

为了确保我的网站的跨浏览器兼容性,我总是自己定义正文边距。在本例中: html, body {margin: 0 0 0 0;填充:0 0 0 0; }
直到我学习了相当多的 CSS 知识后,我才意识到正文有自己预定义的边距和填充。

To ensure cross-browser compatibility to my websites, I always define the body margins myself. In this case: html, body {margin: 0 0 0 0; padding: 0 0 0 0; }
I didn't realize that the body had it's own pre-defined margins and padding until I had learned quite a bit of CSS.

祁梦 2024-10-15 11:58:49

因为 padding 和/或 margin (取决于浏览器)对于 html 和/或 body 来说不为零默认情况下,内边距和边距环绕内容高度。

Because padding and/or margin (depending on the browser) are non-zero for html and/or body by default, and padding and margin wrap around the content height.

仄言 2024-10-15 11:58:49

所有浏览器都有自己的小怪癖,它们显示选择器和属性的方式也略有不同,因此 BoltClock 答案所做的只是确保所有浏览器都以零边距和零填充开始处理。

如果您搜索 CSS Reset,您会找到更多相关信息。

All browsers have their little quirks and they also slightly display selectors and attributes differently so what BoltClock answer is doing is just making sure that all browsers deal with start of with a margin of zero and a padding of zero.

If you do a search for CSS reset you will find more information about it.

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