代码之家  ›  专栏  ›  技术社区  ›  Paul Michaels

HTML将表格高度设置为100%

  •  2
  • Paul Michaels  · 技术社区  · 15 年前

    我试过这么做,但似乎被忽视了。我发现有几篇文章说,如果您想这样做,那么您必须确保父对象也是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%的身高吗?

    2 回复  |  直到 15 年前
        1
  •  6
  •   Treb    15 年前

    我相信这也取决于浏览器,实现方式有点不同…
    但尝试设置 <html> 高度也达到100%,因为它是周围的元素 <body> . 等级制度是 html gt; body gt; table 如果最外层的元素没有设置为100%,那么内部的元素就不能再大。

    编辑:
    仔细看一下您的源代码,我相信您的表实际上位于 HTML gt; 身体 gt; form gt; 桌子 所以,也许你也需要将窗体高度设置为100%。我注意到你的 <head> 设置为100%,最好去掉它,因为 <头& 不是表层次结构的一部分。你从来没有为 <头& 可能会混淆渲染引擎…

        2
  •  2
  •   Ivo    15 年前

    查看此网站,希望它有帮助: http://apptools.com/examples/tableheight.php