html - 如何使 HTML 表格行适合其内容

标签 html css

我的 <table>有三行和三列,最后一个表行是这样的:

<tr>
 <td colspan="3" align="center" valign="top" style="background-color: #eeeeee;">
  <hr class="vdivider">
  <div class="sitemap">There's an unordered list in here</div>
 </td>
</tr>

现在我想不通的是 <tr>几乎是其内容的两倍。两者 <hr><div> together sit quite nicely aligned to the top of the table row, 然后有几乎 150px 的空白空间到表的底部。所有元素的填充、边距和边框均为 0,除此之外,表格或其行/列没有太多其他样式:

html, body, table {
  width: 100%;
  height: 100%;
}

如何使表格行适合其内容的高度,并摆脱底部的大空间?我在这里为表格分配了高度,以确保如果窗口比表格大,它会延伸到窗口的底部。我假设那是过大的地方 <tr>起源。为了弥补这一点,我尝试添加额外的 <tr>在站点地图上方带有 min-height:100px; max-height:none;但这没有帮助。

编辑修正错别字。

编辑 或许有更多背景知识。

+--------------------------------+  browser window (html body)
| +----------------------------+ |
| |       banner image         | |  there is a banner image here that stretches across the page
| +----------------------------+ |
| | css menu bar               | |  a standard CSS menu built from ul
| +----------------------------+ |  this is where the table starts, it has three columns
| |  td   |  td           | td | |
| |       |               |    | |
| +----------------------------+ |
| | tr colspan=3 to make space | |  there's column to make space between content above and sitemap below
| +----------------------------+ |
| | tr colspan=3 for sitemap   | |  tr from above, the sitemap which stretches way down if table { height: 100%; }
| +----------------------------+ |
|                                |  this is the space in large windows when table has no height setting.
+--------------------------------+

最佳答案

感谢您的反馈!删除 table { height: 100%; }不起作用,因为它不会将表格拉伸(stretch)到页面底部。这种拉伸(stretch)是我想要的,但我认为这也是导致过度膨胀的原因 <tr>这个问题指的是什么。

这个问题的解决方案更像是一个意外:

<tr style="height: 0;">
  ...
</tr>

有了这个,行缩小到其内容的大小,而表格仍然延伸到页面底部。不确定这是否是一个“健康”的解决方案,但肯定有效。

关于html - 如何使 HTML 表格行适合其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17342181/

相关文章:

CSS 下拉菜单删除边框

css - typo3 rootline 不起作用,在子页面上父级不是 ACT

html - 水平居中图像

html - 如何在 Bootstrap 面板标题中向右显示所有按钮?

php - 仅在 mysql 数据库中插入一次。

jQuery slideToggle 不适用于 <ul>

JQueryUI 拖动一个包含图像的 div

jquery - 更改 jquery 移动 ListView 背景颜色

javascript - 插件设置页面单选按钮无法正常工作

javascript - 如何在输入类型文本(文本字段)内创建表格?