Jane Jane - 13 days ago 8
CSS Question

Assign CSS class to <td> based on header info

Is there any way I can assign a css class to a table cell merely based on its header attribute?

The code is generated dynamically through a CMS so it's a little difficult to change, and it basically looks like this:

<td headers="blue">


How can I assign the style below to the td?

{
background-color: #1374bf;
}

Answer

You can use the css attribute selector.

td[headers="blue"]{
    background-color: #1374bf;
}