2012-07-25 145 views
0

我希望我的表格或div覆蓋用戶屏幕的全部百分比,但「100%」高度不起作用。我正在嘗試使用jQuery來獲取屏幕大小,我可以做什麼,但是如何將它放在表格高度代碼中?jQuery將屏幕高度變化表格設置爲高度

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>For The Holy Church</title> 
<style type="text/css"> 
body { 
    background-image: url(images/BG.jpg); 
    background-repeat: repeat; 
    background-color: #181818; 
    margin: 0px; 
    height: 100%; 
} 
#Main { 
    background-image: url(images/HolyBG.jpg); 
    background-repeat: repeat-y; 
    background-position: center top; 
    height: 100%; 
} 
</style> 
</head> 

<body> 
<table width="100%" height="100%" border="3" cellpadding="0" cellspacing="0" id="Main"> 
    <tr> 
    <td valign="top"><table width="100%" height="100px" border="0" cellpadding="0" cellspacing="0" background="images/TopBG.jpg"> 
     <tr> 
     <td>&nbsp;</td> 
     </tr> 
    </table> 
     <table width="100%" height="350px" border="0" cellpadding="0" cellspacing="0" background="images/VaticanBG.jpg"> 
     <tr> 
      <td><table width="100" border="0" align="center" cellpadding="0" cellspacing="0"> 
      <tr> 
       <td><img src="images/banner/01.jpg" alt="" width="933" height="350" /></td> 
      </tr> 
      </table></td> 
     </tr> 
    </table> 
     <pre><script>$(document).ready(function() { 
    $("p").text(screen.height); 

}); 
</script> 
<br /> 
     </pre> 
     <p>&nbsp;</p> 
     <p>&nbsp;</p></td> 
    </tr> 
</table> 
</body> 
</html> 

我的問題是,該表僅竟把內容,而不是屏幕的高度。

+0

如果你的div不是直接的身體的孩子,它會得到它的父母的100%,而不是身體(從而屏幕)。 – 11684 2012-07-25 19:19:24

回答

1

你應該張貼一些代碼,但你可能還需要確保htmlbody也有height:100%作爲你的div是內那些。

0
body: {height:100%;width:100%;} 

div: {height:100%;width:100%;} 

table: {height:100%;width:100%;} 
0

表的每個父元素都應該將其高度設置爲100%。

百分比高度僅將元素的高度設置爲其父級的100%。它不會比這更大。

例如:

​​

對於表格上方以填充屏幕,它的每一個父:DIV,身體和html標籤必須具有其高度設定爲100%。

相關問題