Skip to content

td:nth-child() counts grid columns, so a colspan or rowspan before the cell shifts it #528

Closed

Description

@jakejackson1

Part of #520 (step 8).

td:nth-child() and th:nth-child() are matched against $this->mpdf->col, the cell's column in the grid, not its position among the cells of its row. td:first-child is not supported at all, even in tables.

Measured on gravitypdf at b6a07921, PHP 8.5.4.

Rule Row Browser mPDF
td:nth-child(2) {color:green} <td colspan="2">a</td><td>X</td> X green X black
td:nth-child(3) {color:red} <td colspan="2">a</td><td>X</td> X black X red
td:nth-child(1) {color:green} <td>X</td>, in the row under a rowspan="2" cell X green X black
td:first-child {color:green} <td>X</td><td>b</td> X green X black

Fix. Count the cells opened in the current row inside Td, and match td/th:nth-child against that count. Treat :first-child on td, th and tr as :nth-child(1). This needs no stack of open elements; #538 later counts every element this way.

Tests. A colspan and a rowspan before the cell, header and footer rows, and :first-child.

Related: #526.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions