Skip to content

Table cell vertical alignment impacted by line-height #12531

Closed

Description

@adamncasey
<html>
<head>
</head>
<body>
    <table>
            <tr>
                <td style="line-height:32pt;">Should be</td>
                <td>Level</td>
            </tr>
    </table>
</body>
</html>

In Firefox, Chrome & Edge the text in these two cells is vertically aligned.

In Servo, the text in the first cell (with larger line-height applied) appears lower on the page than the text in the second cell.

I had a look around layout/table*.rs but failed to make much headway. In

fn assign_block_size_table_row_base(&mut self, layout_context: &LayoutContext) {
the child cells of the row are assigned the correct heights (comparing computed cell height values against other browsers). Even so, the text in the cell without a line-height style still appears as if the entire row is the height of the smaller cell.

Activity

  1. added
    C-has-manual-testcase
    on Jul 21, 2016
  2. adamncasey commented on Jul 23, 2016

    @adamncasey
    ContributorAuthor

    I found that most of the code to handle this was already there in the previously linked table_row.rs code. The child table-cells' block sizes were updated with the new value. However this stage of table row layout seems to only happen after the table cells have been laid out, which meant the adjusted block size did not affect the visual layout.

    The problem could be fixed if the table-cells are reflow'ed after their new block sizes are calculated. However, after talking to @pcwalton and then looking closer at whether double table-cell layout is really necessary, I think it should be possible to simply adjust the position of the cells during the table row layout code.

    A quick fix which implements this seems to work for the example above renders correctly. This quick fix also places the centre text in the ycombinator news title bar in the correct alignment. At least one wpt test has regressed, so I will look into this next.

    https://github.com/adamncasey/servo/tree/table-row-cell-height

  3. notriddle commented on Jul 25, 2016

    @notriddle
    Contributor

    The problem with moving the cell itself is that it causes the border and background of the cell to move as well. The cell itself is not subject to alignment; it's contents are.

    A more correct way to go about this would be to have the vertical alignment code that's already in table_cell.rs run after the final cell-height-maximize pass.

  4. adamncasey commented on Jul 25, 2016

    @adamncasey
    ContributorAuthor

    Good point. Updated the test to catch that.

    It'll also be easier to implement vertical-align: baseline from the code in table_cell.rs sometime after this

  5. added 4 commits that reference this issue on Jul 26, 2016
    b75a5bf
    4f4ba4a
    148c8e3
    b374582
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layout/tableC-has-manual-testcase

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions