为什么 min-height 在我的页面上不起作用?
我对 body 元素的背景应用了渐变。然后我有一个容器(就在正文之后),其中应用了背景 .png 图像。渐变始终扩展至至少 100% 窗口高度,但容器 (#body2) 不会。
对于为什么这不起作用有什么建议吗?您可以在此处检查我的网页上的 HTML:http://www.savedeth.com/parlours/
I have a gradient applied to the background of the body element. Then I have a container (right after body) that has a background .png image applied to it. The gradient always expands to at least 100% window height but the container (#body2) does not.
Any suggestions to why this doesn't work? You can inspect the HTML on my web page here: http://www.savedeth.com/parlours/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在
html
、body
和#body2
元素上指定height: 100%
(第 1358 行)。未在 IE 6 中测试,但可以在 7 中运行。
Specify
height: 100%
on thehtml
,body
and#body2
elements (line 1358).Not tested in IE 6, works in 7 though.
使用 vh 而不是 % 对我有用,无需使用任何额外的技巧。
这就是我所拥有的:
其中 .wrapper 是您应用于容器/包装器或您希望拉伸屏幕高度的整个长度的内容主体的类。
当包装器内的内容小于或大于屏幕高度允许时,这将按照您的预期工作。
这应该适用于大多数浏览器。
Using vh instead of % worked for me without having to use any extra tricks.
This is what I have:
Where .wrapper is the class you apply to your container/wrapper or main body of content that you wish to stretch the full length of the screen height.
This will work as you would expect it to when the content within the wrapper is less or more than the screen height allows.
This should work in most browsers.
您将最小高度设置为 100%,这只会与填充空间的任何元素一样高。以像素表示最小高度。另外,请注意 IE6- 需要它自己的一组规则。请参阅http://davidwalsh.name/cross-browser-css-min-height 了解更多详情。
You have your min-height set to 100% which will only be as tall as any elements that fill the space. Express you min-height in terms of pixels. Also, note that IE6- requires it's own set of rules. See http://davidwalsh.name/cross-browser-css-min-height for more details.
position:absolute;
适用于大多数情况。例如:position: absolute;
works in most cases. For example:完整答案
Complete Answer
有些东西将你的 body 元素的高度设置为 320px(如果你查看 chrome 的检查元素),
因此 100% 是 320px。这就是为什么它仅以 320 像素高度的 100% 显示在页面顶部。
您必须设置一个高度才能使最小高度发挥作用。
所以一般情况下设置高度@100%应该可以。
something is setting the height of your body element to 320px (if you look in chrome's inspect element)
therefore 100% is of 320px. that is why is it only showing on the top of the page with 100% of 320 px height.
you have to set a height for the min-height to work.
so set the height @ 100% in general should work.
拧紧它。谁没有 javascript 呢?特别是对于这个人群。
Screw it. Who doesn't have javascript anyways? Especially for this demographic.