CSS:100% 高度问题

发布于 2025-01-08 17:46:09 字数 1165 浏览 1 评论 0原文

我知道有很多关于 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 技术交流群。

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

发布评论

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

评论(3

墨小墨 2025-01-15 17:46:09

绝对定位的元素不会以任何方式影响包装元素。因此,div#static-maincontent 的高度并没有真正转换为 div#static-content...它只是漂浮在所有其他元素之上。

  • 删除所有position:absolute
  • 给div#sidebar一个float:left
  • 给div#static-maincontent一个float:right
  • 添加类似的东西
    在 div#static-maincontent 和 INSIDE div#static-content 之后
  • 从 div#static-content 中删除 height: 100%

这应该可以工作(至少对于 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.

  • Remove all position:absolute
  • give div#sidebar a float:left
  • give div#static-maincontent a float:right
  • add something like <div style="clear:both;"> after div#static-maincontent and INSIDE div#static-content
  • remove height: 100% from div#static-content

This should work (at least with firebug).

删除会话 2025-01-15 17:46:09

在你的 css 中更改以下内容(使用 firebug 进行测试 - 有效)--

#static-content {
width: 960px;
background-color: white;
margin:0 auto;
position: relative;
height: auto;
overflow: hidden;
}
#sidebar {
width: 320px;
height: 100%;
overflow-y: visible;
float: left;
}
#static-maincontent {
width: 600px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #AC740C;
overflow-y: visible;
height: 100%;
float: left;
}

change the following in your css ( tested it using firebug - works ) --

#static-content {
width: 960px;
background-color: white;
margin:0 auto;
position: relative;
height: auto;
overflow: hidden;
}
#sidebar {
width: 320px;
height: 100%;
overflow-y: visible;
float: left;
}
#static-maincontent {
width: 600px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #AC740C;
overflow-y: visible;
height: 100%;
float: left;
}
只有影子陪我不离不弃 2025-01-15 17:46:09

我相信这实际上会解决你的问题。 http://jsfiddle.net/AVRMy/1/

删除了:

overflow-y: visible;
height: 100%;

我从你所有的CSS中 添加: 。

        <div style="clear: both; width: 100%;"></div>

。然后在 div static-maincontent 的结束标记后面

I believe this will actually solve your problem. http://jsfiddle.net/AVRMy/1/

I got rid of:

overflow-y: visible;
height: 100%;

from all your CSS. Then added:

        <div style="clear: both; width: 100%;"></div>

right after the closing tag for the div static-maincontent.

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