2010-08-23 100 views
2

我试过这样做,但它似乎只是被忽略。我发现一些文章说,如果你想这样做,那么你必须确保父对象也是100%。我有以下内容:HTML设置表的高度为100%

<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server" style="height:100%"> 
    <title>Untitled Page</title> 
    <asp:ContentPlaceHolder id="head" runat="server"> 
    </asp:ContentPlaceHolder> 
    <style type="text/css"> 
     .MasterStyle 
     { 
      width: 98%;    
      height: 100%; 
     } 
     .ContentStyle 
     {   
      width: 100%; 
     } 
     .TableStyle 
     { 
      width: 133px;      
      height: 100%; 
     } 
    </style> 
</head> 
<body class="MasterStyle"> 
    <form id="frmMaster" runat="server"> 
    <div class="ContentStyle">   
     <asp:Label runat="server" Text="My Site Name" Font-Bold="true" Font-Names="MS-Sans" 
      Style="text-align:right" Width="100%" /> 
     <br />   
    </div> 
    <hr /> 
    <table style="width:100%; height:100%" border="true"> 
     <tr> 
     <td class="TableStyle" style="height:100%">  

我在桌子周围有一个边框,可以看到它没有填充高度。谁能告诉我为什么我没有获得100%的身高?

回答

6

我相信这也是依赖于浏览器中,实现改变一点点...
但尝试设置<html>至100%的高度,以及,因为它是围绕<body>的元素。层次结构为html>body>table,如果最外层元素未设置为100%,则内层元素不能变大。

编辑:
看你的源代码更接近,我相信你的表实际上是坐在html>body>form>table,所以也许你的东东设置表格高度为100%,太。我注意到你的<head>设置为100%,最好删除它,因为<head>不是你的表的层次结构的一部分。你从来没有如何设置高度<head>可能会混淆渲染引擎...

+2

谢谢。设置表单和HTML工作。但是,我收到一个编译警告,说没有HTML的样式属性! – 2010-08-23 07:24:53