Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for nth-last pseudo class selectors #199

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

bechte
Copy link

@bechte bechte commented Dec 12, 2024

With this commit the following CSS3 pseudo classes will be supported:

  • :nth-last-child(an+b) and
  • :nth-last-of-type(2a+b)

This is especially helpful to format tables with a fixed number of columns, by using a combination of :nth-child and :nth-last-child.

Example, given the following markup:

<html>
<body>
  <table>
    <tr>
      <th>First Column</th>
      <th>Second Column</th>
      <th>Third Column</th>
      <th>Fourth Column</th>
      <th>Fifth Column</th>
    </tr>
    <tr>
      <td>Line 1a</td>
      <td>Line 1b</td>
      <td>Line 1c</td>
      <td>Line 1d</td>
      <td>Line 1e</td>
    </tr>
  </table>

  <table>
    <tr>
      <th>First Column</th>
      <th>Second Column</th>
      <th>Third Column</th>
      <th>Fourth Column</th>
    </tr>
    <tr>
      <td>Line 1a</td>
      <td>Line 1b</td>
      <td>Line 1c</td>
      <td>Line 1d</td>
    </tr>
  </table>
</body>
</html>

The following styles can be used to format the tables, such that the four-column table's last three columns will align with the last three columns of the five-column table:

table tr th:nth-child(1):nth-last-child(5) { width: 30%; }
table tr th:nth-child(2):nth-last-child(4) { width: 10%; }
table tr th:nth-child(3):nth-last-child(3) { width: 20%; }
table tr th:nth-child(4):nth-last-child(2) { width: 20%; }
table tr th:nth-child(5):nth-last-child(1) { width: 20%; }

table tr th:nth-child(1):nth-last-child(4) { width: 40%; }
table tr th:nth-child(2):nth-last-child(3) { width: 20%; }
table tr th:nth-child(3):nth-last-child(2) { width: 20%; }
table tr th:nth-child(4):nth-last-child(1) { width: 20%; }

With this commit the following CSS3 pseudo classes will be supported:
- :nth-last-child(an+b) and
- :nth-last-of-type(2a+b)

This is especially helpful to format tables with a fixed number of
columns, by using a combination of :nth-child and :nth-last-child.

Example, given the following markup:
```
<html>
<body>
  <table>
    <tr>
      <th>First Column</th>
      <th>Second Column</th>
      <th>Third Column</th>
      <th>Fourth Column</th>
      <th>Fifth Column</th>
    </tr>
    <tr>
      <td>Line 1a</td>
      <td>Line 1b</td>
      <td>Line 1c</td>
      <td>Line 1d</td>
      <td>Line 1e</td>
    </tr>
  </table>

  <table>
    <tr>
      <th>First Column</th>
      <th>Second Column</th>
      <th>Third Column</th>
      <th>Fourth Column</th>
    </tr>
    <tr>
      <td>Line 1a</td>
      <td>Line 1b</td>
      <td>Line 1c</td>
      <td>Line 1d</td>
    </tr>
  </table>
</body>
</html>
```

The following styles can be used to format the tables, such that the
four-column table's last three columns will align with the last three
columns of the five-column table:
```
table tr th:nth-child(1):nth-last-child(5) { width: 30%; }
table tr th:nth-child(2):nth-last-child(4) { width: 10%; }
table tr th:nth-child(3):nth-last-child(3) { width: 20%; }
table tr th:nth-child(4):nth-last-child(2) { width: 20%; }
table tr th:nth-child(5):nth-last-child(1) { width: 20%; }

table tr th:nth-child(1):nth-last-child(4) { width: 40%; }
table tr th:nth-child(2):nth-last-child(3) { width: 20%; }
table tr th:nth-child(3):nth-last-child(2) { width: 20%; }
table tr th:nth-child(4):nth-last-child(1) { width: 20%; }
```
@bechte
Copy link
Author

bechte commented Dec 12, 2024

To all maintainers:

It would be wonderful to have this feature available in 8.0.6. We are using the library within a project and our lives would be much more easier if the support for styling tables with the :nth-last-child pseudo class can be applied.

Looking forward to hearing back from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant