HTML表格单元格的默认宽度是什么?< td&gt ;? [英] What is the default width of an HTML table cell <td>?

查看:821
本文介绍了HTML表格单元格的默认宽度是什么?< td&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到此问题的答案:在规范或UA文档中的位置是< td> define?

I haven't been able to find the answer to this question: Where in the spec or in UA documentation is the default width of a <td> defined?

我搜索了 HTML Living Standard HTML5建议和各种其他来源。

I've searched the HTML Living Standard, the HTML5 Recommendation, and various other sources.

我的理解(基于使用和观察) ,默认情况下,占用它居住的列的全宽。

My understanding (based on usage and observation) is that a table cell will, by default, occupy the full width of the column in which it lives. And the cell cannot be given a different width than the column if other cells exist in the column.

我正在寻找这种行为的官方确认,最好是在W3C或者用户代理文件。

I'm looking for official confirmation of this behavior, preferably in W3C or user agent documentation. But any authoritative reference is acceptable.

推荐答案

表格单元格的物理/可视宽度不是由HTML定义的,而是由CSS定义的。 CSS 2.1规范的整个部分专门用于表格布局,用于补充HTML的描述表格数据。

The physical/visual width of a table cell is defined not by HTML, but by CSS. The CSS 2.1 specification has an entire section dedicated to table layout that complements HTML's description of tabular data.

此外,CSS本身未完全定义如何计算单元格的宽度。它使用固定表布局算法:

Furthermore, CSS itself does not fully define how the width of a cell is calculated. It does with the fixed table layout algorithm:


在固定表布局算法中,每列的宽度确定如下: p>

In the fixed table layout algorithm, the width of each column is determined as follows:


  1. width属性的值不是auto的列元素会设置该列的宽度。

  2. 否则,第一行中width属性的值不为auto的单元格确定该列的宽度。

  3. 任何剩余的列均匀地划分剩余的水平表空间(减去边框或单元格间距)。
  4. 如果单元格跨越多个列,
  1. A column element with a value other than 'auto' for the 'width' property sets the width for that column.
  2. Otherwise, a cell in the first row with a value other than 'auto' for the 'width' property determines the width for that column. If the cell spans more than one column, the width is divided over the columns.
  3. Any remaining columns equally divide the remaining horizontal table space (minus borders or cell spacing).

表的宽度是表格元素的width属性值和列宽之和(加细胞间距或边界)。如果表格比列宽,则额外的空格应该分布在列上。

The width of the table is then the greater of the value of the 'width' property for the table element and the sum of the column widths (plus cell spacing or borders). If the table is wider than the columns, the extra space should be distributed over the columns.

自动表布局的粗略指南,用户代理可以自由地遵循或偏离(它列出了与固定表布局不同的分步过程,但是整个列表是非规范的)。 一般来说,您可以在大多数 常见情景 - 如你所观察到的,自动大小的表格单元通常占用其内容所需的空间,而不再占用。但深入探讨边缘情况,你会发现各种各样的疯狂

but it doesn't give anything beyond a rough guideline for auto table layout, which user agents are free to follow or deviate from (it lists a step-by-step procedure not unlike that of fixed table layout, but that entire list is non-normative). Generally you can expect consistent behavior from UAs in the most common scenarios — as you observe, an auto-sized table cell generally takes up as much space as required by its content, and no more. But dig into edge cases, and you'll find all sorts of crazy.

这篇关于HTML表格单元格的默认宽度是什么?&lt; td&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆