html – Div高度100%,不包括标题

前端之家收集整理的这篇文章主要介绍了html – Div高度100%,不包括标题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
好的,所以我知道这个主题有很多问题,但我仍然无法确切地知道如何使这项工作. This接近问题,但它不适合我.

我希望我的页面有100%的高度.在此页面内是一个高度为40px的静态标题,然后是剩余高度(100% – 40px)的内容.

HTML:

  1. <body>
  2. <div id="page">
  3. <div id="header">
  4. header
  5. </div>
  6. <div id="content">
  7. content
  8. </div>
  9. </div>
  10. </body>

CSS:

  1. html,body
  2. {
  3. height: 100%;
  4. margin: 0px;
  5. }
  6.  
  7. #page
  8. {
  9. min-height: 100%;
  10. }
  11.  
  12. #header
  13. {
  14. height: 40px;
  15. }
  16.  
  17. #content
  18. {
  19. height: 100%;
  20. position: absolute;
  21. top: 0;
  22. padding-top: 40px;
  23. }

这是代码的解释:

>我添加了位置:绝对内容,因为否则由于某种原因它不会占用其容器#page的100%
>然后问题是它超出了页面的边界,这就是我添加top:0的原因.
>然后#content的内容标题重叠,所以我添加了padding-top:40px
>现在#content再次超出了页面的边界

有什么建议?谢谢.

解决方法

这应该工作:

http://jsfiddle.net/94JNZ/1/

  1. #content
  2. {
  3. height: auto;
  4. width: 100%;
  5. position: absolute;
  6. top: 40px;
  7. bottom: 0;
  8. }

猜你在找的HTML相关文章