Search code examples
csscss-selectorspseudo-elementpseudo-class

Multiple selector with the same pseudo-class


Is there a neater way to have one pseudo-class for multiple selector?

For example:

th:first-of-type, td:first-of-type {
    text-align: left;
}

Solution

  • Not in CSS, but if you were using a preprocessor like Sass you could organize it a bit like this. (Note that the CSS produced will still compile to your original example.)

    th,
    td {
      &:first-of-type {
        text-align: left;
      }
    }