liveBook · Manning

Nth-of-type pseudo-class

As explained in Tiny CSS Projects

The CSS :nth-of-type pseudo-class selects elements according to their position among sibling elements of the same type.

The :nth-of-type() pseudo-class selects an element according to its position among sibling elements of the same type. Its argument can be a number, a keyword such as even, or a pattern such as n+3. section 8.2.4 section 8.6

Use positional patterns to style meaningful parts of a checkout table:

  • Select the second cell in every body row with tbody td:nth-of-type(2). section 8.2.4
  • Select alternating body rows with tbody tr:nth-of-type(even), creating a light striped background. section 8.2.4
  • Select the third and later cells with :nth-of-type(n+3), then apply the rule only at wider viewport sizes. section 8.4.1

Emphasize item names

tbody td:nth-of-type(2) { font-weight: bold; } This targets the second td in each table-body row, making the item name stand out without adding a class to every cell. section 8.2.4

Listing 8.25 Right-aligning contents
@media (min-width: 550px) {
  th:nth-of-type(n+3),
  td:nth-of-type(n+3) {
    text-align: right;
  }
}

See the responsive n+3 selector applied to headers and cells from the third column onward. section 8.4.1

How Tiny CSS Projects covers it

How deep it goes
Explains same-type sibling matching and demonstrates numeric, keyword, and n+3 patterns through applied table rules.
Examples
Uses bold item cells, striped even rows, and right-aligned third-and-later columns in a checkout table.
What it assumes
Assumes basic CSS selectors and HTML table structure while explaining positional matching through concrete table styling.
What you can do after
Apply it via CSS selectors to emphasize cells, stripe rows, and align later table columns.
How it connects
Connects positional selection with HTML tables, responsive design, media queries, and text alignment.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.