CSS高度100%问题

发布于 2024-11-17 15:47:26 字数 873 浏览 1 评论 0原文

我知道有很多关于 css 100% 高度问题的问题。 但是我尝试按照那里的说明进行操作,但高度仍然不是 100%, 所以我想我会再问这个问题。

您可以看到问题的网站是:

www.exendo.be

一些 css 样式:

html {
    height: auto !important;
    margin: 0;
    min-height: 100%;
    padding: 0;
}

body {
    background: url("/wp-content/uploads/2011/06/bg.png") repeat-x scroll 0 100px #F2F7E8;
    height: auto !important;
    margin: 0;
    min-height: 100%;
    padding: 0;
    width: 100%;
}

wrapper {
    height: auto !important;
    min-height: 100%;
    position: relative;
}
footer-container {
    background: url("/wp-content/uploads/2011/06/exendo-footer_bg.png") no-repeat scroll center bottom #557F40;
    height:146px;
}

正如您在网站,页脚在页面上太高。 如果我用 Firebug 检查页面,我可以看到 html 的高度是 100%,但 body 标签不是。 该问题在 Firefox 和 IE 上均出现。

如果有人能提供帮助那就太好了!

I know there are a lot of questions about a css 100% height problem.
However I've tried to follow the instructions there and still the height isn't 100%,
so I thought I'd ask the question again.

The site where you can see the problem is:

www.exendo.be

some css styles:

html {
    height: auto !important;
    margin: 0;
    min-height: 100%;
    padding: 0;
}

body {
    background: url("/wp-content/uploads/2011/06/bg.png") repeat-x scroll 0 100px #F2F7E8;
    height: auto !important;
    margin: 0;
    min-height: 100%;
    padding: 0;
    width: 100%;
}

wrapper {
    height: auto !important;
    min-height: 100%;
    position: relative;
}
footer-container {
    background: url("/wp-content/uploads/2011/06/exendo-footer_bg.png") no-repeat scroll center bottom #557F40;
    height:146px;
}

As you can see on the site, the footer is too high on the page.
If I inspect the page with Firebug, I can see that the html is 100% height, but the body tag isn't.
The problem both occurs on Firefox and IE.

If anybody could help that would be great!

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

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

发布评论

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

评论(3

活泼老夫 2024-11-24 15:47:26

多人建议立场:绝对;底部:0;

如果内容比容器高,这可能会导致问题。高度不会增加,因此内容将不再适合,并且可能会被切断或导致丑陋的滚动条。

如果您可以为容器指定固定高度,这是理想的选择,因为 height:100% 将在子元素上起作用。如果内容太大,您可以在子级上放置背景,并在父级上溢出:可见,以便内容仍然显示。这会有所帮助,但除非子级与父级宽度相同,否则它仍然可能会中断。

如果这不起作用,我建议使用 em 或像素的最小高度。这将确保高度填充父级,并在内容太长时扩展。这最适合 www.baka.ca 上的客户评论

A number of people suggested position:absolute; bottom:0;

This can cause an issue if the content is taller than the container. The height will not increase so the content will no longer fit and can get cut off or result in ugly scroll bars.

If you can give a fixed height to the container, this is ideal since the height:100% will then work on the child element. In case the content is too large, you can put a background on the child with overflow:visible on the parent, so the content still displays. This helps, but it can still break unless the child is the same width as the parent.

If that doesn't work, I recommend using min-height in em or pixels. This will make sure the height fills the parent, and expands if the content is too long. This worked best for customer comments on www.baka.ca

做个ˇ局外人 2024-11-24 15:47:26

我认为这篇文章可以帮助您。

根据这篇文章:

将“position:relative”分配给您的“容器”div - 页面、页面容器或包装器(我不确定三者中的哪一个,只需尝试),然后“position:absolute;”底部:0;”到你的“页脚容器”div。

我希望这对你有帮助。

I think this article can help you.

According to this article:

Assign "position:relative" to your "container" div - page, page-container, or wrapper (I'm not sure to which one of the three, just try), and then "position:absolute; bottom:0;" to your "footer-container" div.

I hope that helps you.

戏蝶舞 2024-11-24 15:47:26

@denappel;给出 html & body 100% heightfooter 放在 main div 包装 之外根据页脚的高度,在 minus 中指定 margin-bottom。

css:

.wrapper {
    position: relative;
    width: 700px;
    font-size: 0.9em;
    margin: 0 auto -142px;
    background:yellow;
}
.header {
    height: 190px;
    background:green;
}

.footer {
    position: relative;
    width: 700px;
    margin: 0 auto;
    background:red;
}

* {
    margin: 0;
}
html, body {
    height: 100%;
}
.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -142px;
.footer, .push {
    height: 142px;
}

检查此示例
http://jsfiddle.net/sandeep/tCdPX/3/

这在功能上称为stickyfooter

@denappel; give html & body 100% height put footer outside of your main div wrapper & give margin-bottom in minus according to the height of footer.

css:

.wrapper {
    position: relative;
    width: 700px;
    font-size: 0.9em;
    margin: 0 auto -142px;
    background:yellow;
}
.header {
    height: 190px;
    background:green;
}

.footer {
    position: relative;
    width: 700px;
    margin: 0 auto;
    background:red;
}

* {
    margin: 0;
}
html, body {
    height: 100%;
}
.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -142px;
.footer, .push {
    height: 142px;
}

check this example
http://jsfiddle.net/sandeep/tCdPX/3/

this functionally called stickyfooter

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