Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

html - Default value of vertical-align for table cells

According to the spec, the default value of vertical-align is baseline.

baseline

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.

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

middle

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

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As said by the spec, the initial value of vertical-align is always baseline:

vertical-align

  • Initial: baseline

However, as explained in The cascade,

Conforming user agents must apply a default style sheet (or behave as if they did).

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.

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

And that recommended stylesheet contains

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

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...