CSS - Select all table cells <td> or <th> in a table

css, html

Solution

Figured out a much shorter version. I remembered that you can use asterisk * for any element. Knowing that the table tag may only immediately contain tbody/thead, and tr may only immediately contain td/th, I revised the CSS class to the following:

.p1 > * > tr > * {
    background-color:blue;
}

Problem

I want to style all table cells with background-color:blue, when they are inside a table with class="p1". The following works, but it is long: ``` table.p1 > tbody > tr > td, table.p1 > thead > tr > td, table.p1 > tbody > tr > th, table.p1 > thead > tr > th{ background-color:blue; } ``` Is there a shorter/more elegant way to define this CSS rule? Edit: only the table cells immediately contained by table "p1" may be styled, and no further children (such as nested tables inside those cells)

Original source