【问题标题】:css div height 100% problem?css div高度100%的问题?
【发布时间】:2009-12-12 11:04:23
【问题描述】:

我想要一个 div 占据所有屏幕高度,这就是我找到以下链接的原因:

技巧:使容器具有指定的高度,例如:body{height:100%} 似乎工作正常,但是,我发现:一旦添加了一些 doctype 声明,例如:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

它不起作用,至少在 Firefox 3.* 上不起作用。有什么建议吗?

【问题讨论】:

    标签: css html height


    【解决方案1】:

    以下内容适用于严格的 HTML 4.01(来自您的第二个链接)。即使body 很长,也不会显示垂直滚动条。这对你有用吗?

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
        <style>
          html, body {
          /* get rid of default spacing on the edges */
          margin: 0;
          padding: 0;
    
          /* get rid of that 2px window border in Internet Explorer 6 */
          border: 0;
    
          /* fill the height of the browser */
          height: 100%;
    
          /* no more scroll bar */
          overflow: hidden;
        }
        </style>
      </head>
      <body>
        <div>
          many many lines of text
        </div>
      </body>
    </html>
    

    【讨论】:

    • 我注意到doctype并不重要,关键是:不仅要在body中添加height:100%,还要在html中添加
    猜你喜欢
    • 1970-01-01
    • 2014-02-27
    • 2011-09-25
    • 1970-01-01
    • 2011-09-15
    • 2010-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多