2

This is a theoretical question about the capabilities of CSS.

I know normal practice is to change this server side, but I was wondering if it's possible to use alternate css based on the content of an element. For example if a table division element contains a 0 style it one colour.

<td class="result">0</td>

And anything higher than 0 style an alternate colour

<td class="result">1</td>

<td class="result">5</td>
blarg
  • 3,773
  • 11
  • 42
  • 71

1 Answers1

2

A way this can be achieved is by using HTML5 data attributes, but this requires you to slightly modify your markup (which usually isn't a problem if it's dynamically generated):

HTML:

<td data-result="1">1</td>

CSS:

td[data-result="1"] { ... }

Working JS Bin

For a full browser support, it's better to use JavaScript.

Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63