The default value for vertical alignment for table cells

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

baseline

Align the baseline with the base of the source field. If the field does not have a baseline, align the edge of the bottom edge with the original baseline.

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

middle

Align the vertical middle of the field with the base level of the parent box, plus half the x-height of the parent.

I would like to have official confirmation of this behavior, but I can not find anything in the W3C documentation. All I found says that the default value is baseline .

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

+9
source share
1 answer

As stated in the spec, the initial vertical-align value is always baseline :

alignment vertical

  • Initial: Baseline

However, as explained in Cascade ,

Relevant user agents should use the default stylesheet (or act as if they were.)

In the default stylesheet for the user agent, document language elements must be represented in ways that satisfy the general expectation for the document language.

See the sample stylesheet for HTML for the recommended default style sheet for HTML documents.

And this recommended style sheet contains

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

Therefore, if you (the source of the original) did not specify values ​​for tbody and td vertical-align , the cascade will extract the middle value from the user agent source.

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

+14
source

Source: https://habr.com/ru/post/1235056/


All Articles