表格单元格垂直对齐的默认值

表格单元格垂直对齐的默认值

本文介绍了表格单元格垂直对齐的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据规范,默认值vertical-alignbaseline.

基线

将框的基线与父框的基线对齐.如果该框没有基线,将底部边距边缘与父母的基线.

Align the baseline of the box with the baseline of the parent box. If the box does not have a baseline, align the bottom margin edge with the parent's baseline.

然而,当涉及到表格单元格 (td) 时,它的默认值似乎总是 middle.

However, when it comes to table cells (td) it appears the default value is always middle.

将框的垂直中点与父级的基线对齐框加上父级 x 高度的一半.

Align the vertical midpoint of the box with the baseline of the parent box plus half the x-height of the parent.

我想对此行为进行官方确认,但我在 W3C 文档中找不到任何内容.我发现的一切都说默认值是 baseline.

I would like official confirmation of this behavior, but I can't find anything in W3C documentation. Everything I've found says the default value is baseline.

哪里说表格单元格vertical-align的默认值是middle?

Where does it say that the default value of vertical-align is middle for table cells?

推荐答案

正如规范所说,vertical-align 总是 baseline:

垂直对齐

  • 初始:基线

但是,如级联中所述,

符合标准的用户代理必须应用默认样式表(或表现得像他们一样).

用户代理的默认样式表应该显示满足一般表示的文档语言对文档语言的期望.

A user agent's default style sheet should present the elements of the document language in ways that satisfy general presentation expectations for the document language.

有关推荐的默认样式,请参见HTML 示例样式表用于 HTML 文档的工作表.

See A sample style sheet for HTML for a recommended default style sheet for HTML documents.

推荐的样式表包含

thead, tbody,
tfoot           { vertical-align: middle }
td, th, tr      { vertical-align: inherit }

因此,如果您(作者来源)没有为 tbodytdvertical-align 提供任何值,级联将从用户代理源中检索 middle 值.

Therefore, if you (author origin) don't provide any value for tbody's nor td's vertical-align, the cascade will retrieve the middle value from the user agent origin.

请注意,默认样式表依赖于实现,因此某些浏览器可能会为不同的元素设置不同的 vertical-align 值.

Note the default style sheet is implementation dependent, so some browsers may set different vertical-align values for different elements.

这篇关于表格单元格垂直对齐的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:27