2009-12-12 126 views
2

我想一個div採取一切屏幕高度,這就是爲什麼我發現下面的鏈接:css div高度100%的問題?

的招數:使容器具有特定的高度,例如:body{height:100%}似乎工作正常,但是,我發現:一旦您添加一些文檔類型聲明,例如:

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

至少在Firefox 3中不起作用。*,它不起作用。有什麼建議麼?

回答

3

以下代碼適用於HTML 4.01 strict(來自您的第二個鏈接)。即使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> 
+0

我注意到文檔類型並不重要,關鍵是:不僅將高度:100%添加到body,還對html – WilliamLou 2009-12-14 19:00:01