471,599 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,599 software developers and data experts.

CSS color conditional on content

for CSS, is it possible to say, if the content in the div or span is
0, show the "0" in red, and if it is a "1", show it in green? I can
use PHP or any script to do it, but it probably is quite handy to let
CSS handle the formatting style without needing server support.

Nov 23 '07 #1
3 2612
Scripsit Summercool:
for CSS, is it possible to say, if the content in the div or span is
0, show the "0" in red, and if it is a "1", show it in green?
Of course not. Read a primer on CSS to get an idea of what CSS is about,
and you won't ask questions like that.
I can
use PHP or any script to do it, but it probably is quite handy to let
CSS handle the formatting style without needing server support.
There's nothing handy about it: it's not possible, and it's not
something that CSS is meant for.

You can use a class attribute to distinguish, say, the elements you
would like to appear in red from those you'd like to be green. However,
you should bear in mind that about 10% of male population are unable to
distinguish red from green well (or at all), so even as auxiliary method
(to highlight a difference that already exists in content, like "0" from
"1"), it's not a good choice.

We heard you the first time, and you crossposted pointlessly, since
c.i.w.a.h. is strictly about HTML, not CSS (and not about server-side
technologies either). Followups trimmed.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Nov 23 '07 #2
Summercool wrote:
for CSS, is it possible to say, if the content in the div or span is
0, show the "0" in red, and if it is a "1", show it in green? I can
use PHP or any script to do it, but it probably is quite handy to let
CSS handle the formatting style without needing server support.
The answer's still "No".
Nov 23 '07 #3
Harlan Messinger wrote:
Summercool wrote:
>for CSS, is it possible to say, if the content in the div or span is
0, show the "0" in red, and if it is a "1", show it in green? I can
use PHP or any script to do it, but it probably is quite handy to let
CSS handle the formatting style without needing server support.
The answer's still "No".
However, you can use JavaScript to do it.
Nov 23 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ed Chiu | last post: by
5 posts views Thread by paulo | last post: by
16 posts views Thread by Alan Jones | last post: by
1 post views Thread by Brian | last post: by
6 posts views Thread by andrew | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.