【发布时间】:2013-06-21 21:09:06
【问题描述】:
我阅读了很多其他问题,但不知道如何将解决方案应用于我的问题。
将我的主要内容 DIV 设置为 100% 高度可以正常工作,除非在 DIV 之外和浏览器顶部添加另一个元素。 100% 的 DIV 保留了浏览器的整个高度,并且不考虑浏览器顶部的新元素。这会导致 DIV 底部的内容被推到视野之外。
详情:
- 一个必需的结果是不放置浏览器滚动条。
- 在生产中,它是一个 DIV,包含一个 100% 宽度和浏览器高度的 FLASH 对象。
- 不完全确定哪个 HTML 版本最适合用于嵌入 FLASH。尽管如有必要,我可以用另一个问题来解决这个问题。
JSFiddle 代码示例:
-
This Shows how the Blue content box should appear normally
body { background-color: #FFFFFF; height: auto; margin: 0; min-height: 100%; overflow: hidden; } #logo { background-color: #000000; height: 40px; width: 100px; display: none; } #panel-1 { background-color: #CCCCCC; display: block; height: 100%; position: fixed; width: 100%; } #panel-content { background: none repeat scroll 0 0 #CCFFEE; bottom: 0; height: 50px; position: absolute; width: 100%; } <div> <div id="header"> <div id="logo"></div> </div> <div style="" id="content-wrapper"> <div id="panel-1"> <div id="panel-content"></div> </div> </div> </div> -
This Shows what happens to the blue box at the bottom when an element is added to the top
body { background-color: #FFFFFF; height: auto; margin: 0; min-height: 100%; overflow: hidden; } #logo { background-color: #000000; height: 40px; width: 100px; } #panel-1 { background-color: #CCCCCC; display: block; height: 100%; position: fixed; width: 100%; } #panel-content { background: none repeat scroll 0 0 #CCFFEE; bottom: 0; height: 50px; position: absolute; width: 100%; } <div> <div id="header"> <div id="logo"></div> </div> <div style="" id="content-wrapper"> <div id="panel-1"> <div id="panel-content"></div> </div> </div> </div>
【问题讨论】:
-
100% 加上某些东西总是超过 100%...
-
哈哈是的。问题是我试图弄清楚在考虑到顶部元素之后如何占用 100% 的剩余空间。一直没搞清楚。
-
为什么不把它放在100%高度的元素里面呢?
-
我尝试过是因为它在 100% 高度元素中导致了与 100% 高度 flash 对象相同的问题。 @Gimmy 的答案似乎有效。