CSS:100% 高度问题
我知道有很多关于 CSS 中 height:100% 声明的帖子,但没有一个能解决我所遇到的问题。
简而言之,这就是我所面临的: http://cornerstonearts.hostasaurus.com/about/cornerstone_history
元素和容器 div 的所有高度设置 – html、body、#static-content、#sidebar、#static-maincontent – 均为 100%:
html {
height: 100%;
}
body {
background-color:#d5af6a;
margin:0;
height: 100%;
}
#static-content {
width:960px;
background-color:#FFF;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
position: relative;
height: 100%;
overflow-y: visible;
}
#sidebar {
width:320px;
position: absolute;
left: 0px;
top: 0px;
height: 100%;
overflow-y: visible;
}
#static-maincontent {
width:600px;
position: absolute;
left: 340px;
top: 0px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #AC740C;
height: 100%;
overflow-y: visible;
}
我读过有几篇文章表明问题可能是使用绝对定位。我不明白这怎么可能是原因。如果 DIV 是绝对定位的,它仍然应该扩展以容纳其内容。
尽管如此,使用 Firebug,我将所有元素更改为相对定位,并使侧边栏和主栏向左浮动。我仍然遇到同样的问题。
这是我确信必须有一个我只是没有看到的简单解决方案的事情之一。毕竟,让页面元素扩展到其容器高度的 100% 有多难?
任何帮助将不胜感激。
谢谢!
I know that there have been a number of posts regarding the height:100% declaration in CSS, yet none of them have resolved the issue I'm struggling with.
In a nutshell, this is what I'm facing: http://cornerstonearts.hostasaurus.com/about/cornerstone_history
All of the height settings for the elements and container divs – html, body, #static-content, #sidebar, #static-maincontent – are 100%:
html {
height: 100%;
}
body {
background-color:#d5af6a;
margin:0;
height: 100%;
}
#static-content {
width:960px;
background-color:#FFF;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
position: relative;
height: 100%;
overflow-y: visible;
}
#sidebar {
width:320px;
position: absolute;
left: 0px;
top: 0px;
height: 100%;
overflow-y: visible;
}
#static-maincontent {
width:600px;
position: absolute;
left: 340px;
top: 0px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #AC740C;
height: 100%;
overflow-y: visible;
}
I read a couple of posts that suggest the problem might be the use of absolute positioning. I didn't see how that could be the cause. If a DIV is absolutely positioned, it should still expand to accommodate its contents.
Nevertheless, using Firebug, I changed all of the elements to be positioned relatively and had the sidebar and main columns float left. I still had the same problem.
This is one of those things that I'm sure must have a simple solution that I'm just not seeing. After all, how hard can it be to have a page element expand to 100% of the height of its container?
Any help would be appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
绝对定位的元素不会以任何方式影响包装元素。因此,div#static-maincontent 的高度并没有真正转换为 div#static-content...它只是漂浮在所有其他元素之上。
这应该可以工作(至少对于 firebug)。
An element positioned absolute doesn't affect the wrapping elements in any way. So the height of your div#static-maincontent doesn't really translate to div#static-content... it just floats above all other elements.
This should work (at least with firebug).
在你的 css 中更改以下内容(使用 firebug 进行测试 - 有效)--
change the following in your css ( tested it using firebug - works ) --
我相信这实际上会解决你的问题。 http://jsfiddle.net/AVRMy/1/
删除了:
我从你所有的CSS中 添加: 。
。然后在 div
static-maincontent
的结束标记后面I believe this will actually solve your problem. http://jsfiddle.net/AVRMy/1/
I got rid of:
from all your CSS. Then added:
right after the closing tag for the div
static-maincontent
.