Search code examples
cssrefactoring

CSS: Select multiple classes' child


I want to select multiple parents' child in CSS in this manner:

(.parent1, .parent2, ...) > child {
    ...
}

Is there any way I can do this without duplicating code:

.parent1 > child,
.parent2 > child,
... {
    ...
}

Solution

  • Use the :is() pseudo-class selector

    :is(.parent1, .parent2, ...) > child {
        ...
    }