代码之家  ›  专栏  ›  技术社区  ›  rafek

修复了HTML中的TD高度属性

  •  3
  • rafek  · 技术社区  · 16 年前

    我不能让td“Date”有固定的高度。如果Body部分的td Date元素比它应该的要大,即使我将Date高度设置为10%,Body高度设置为90%。有什么建议吗?

    <tr>
      <td class="Author" rowspan="2">
        <a href="#">Claude</a><br />
        <a href="#"><img src="Users/4/Avatar.jpeg" style="border-width:0px;" /></a>        
      </td>
      <td class="Date">
        Sent:
        <span>18.08.2008 20:49:28</span>
      </td>
    </tr>
    <tr>
      <td class="Body">
        <span>Id lacinia lacus arcu non quis mollis sit. Ligula elit. Ultricies elit cursus. Quis ipsum nec rutrum id tellus aliquam. Tortor arcu fermentum nibh justo leo ante vitae fringilla. Pulvinar aliquam. Fringilla mollis facilisis.</span>
      </td>
    </tr>
    

    现在我的css是:

    table.ForumThreadViewer td.Date {
      text-align: left;
      vertical-align: top;
      font-size: xx-small;
      border-bottom: solid 1 black;
      height: 20px;
    }
    
    table.ForumThreadViewer td.Body {
      text-align: left;
      vertical-align: top;
      border-top: solid 1 black;
    }
    
    table.ForumThreadViewer td.Author {
      vertical-align: top;
      text-align: left;
    }
    

    它适用于FF,但不适用于IE(

    4 回复  |  直到 16 年前
        1
  •  6
  •   Oli    16 年前

    当你使用百分比时,它们是相对于它们的容器的,即使如此,这也只适用于某些类型的元素。我想,要想让这奏效,你需要将高度应用于 <tr> s、 并给予 <table> 高度。如果 <表> 高度也是相对的,你也需要给它的容器一个高度。

    但是看看你的数据,你是 真正地 你确定你应该用桌子吗?!

        2
  •  2
  •   Prestaul    16 年前

    奥利说得对!然后给出你发布的截图,你使用了错误的标记。你可以使用更像这样的东西:

    <div class="post">
      <div class="author">
        <a href="#">Claude</a><br />
        <a href="#"><img src="Users/4/Avatar.jpeg" /></a>        
      </div>
      <div class="content">
        <div class="date">Sent: 18.08.2008 20:49:28</div>
        <div class="body">
          This is the content of the message.
        </div>
      </div>
      <div class="clear">&nbsp;</div>
    </div>
    

    css如下:

    div.post {
      border: 1px solid #999;
      margin-bottom: -1px; /* collapse the borders between posts */
    }
    div.author {
      float: left;
      width: 150px;
      border-right: 1px solid #999;
    }
    div.content {
      border-left: 1px solid #999;
      margin-left: 150px;
    }
    div.date {
      border-bottom: 1px solid #999;
    }
    div.clear {
      clear: both;
      height: 0;
      line-height: 0;
    }
    
        3
  •  0
  •   Luca    12 年前

    CSS格式

    .Date {
        height: 50px;
    }
    
        4
  •  0
  •   Abhishek Pandey    8 年前

    我不完全理解你的问题,你是说如果你用这个:

    .Date {
     height: 10%
    }
    .Body {
     height: 90%;
    }
    

    那个 .Date td 比它应该的大吗?如果不设定绝对高度,你怎么知道它应该有多大?您是否考虑了边框和填充?

    您可以尝试添加 colspan="2" .Body td 或额外 <td> 只有不间断空格的元素( &nbsp; )