tags:

views:

33

answers:

2

Hi folks,

Quick question. I want to change the color of an int based on the value being positive or negative, using css if possible.

Any ideas??

Thanks again!

A: 

It depends on the language you are using. In just about any language you can set the class of the tags around the value using the dynamic part of the language. If the value doesn't have its own tags you can use <span></span> around the value to give it a class. then you just use the dynamic code to set the class.

If you are using a language like Ruby there are some CSS Selectors Gems you can use but I don't know much about them or if they will help.

RandomBen
+1  A: 

In PHP you could do this:

<span style="color: <?php echo ($var < 0 ? '#FF0000' : '#00FF00'); ?>">Some text</span>

This evaluates the variable $var, if less than zero, applies red to the style (FF0000) otherwise green (00FF00).

JYelton