Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Font Color in Table Row Based on value

Status
Not open for further replies.

ChiSoxFan

Programmer
Aug 30, 2005
4
US
Greetings,

I'm new to CSS and not exactly sure if this can be done.

What I would like to do is have the font color of a row a certain color based on a specific value.

Code:
<table border=1>
  <tr>
    <td>Data 1</td>
    <td>Data 2</td>
    <td>Data 3</td>
    <td>Value</td>
  </tr>
  <tr>
    <td>Sample1a</td>
    <td>Sample1b</td>
    <td>Sample1c</td>
    <td>1</td>
  </tr>
  <tr>
    <td>Sample2a</td>
    <td>Sample2b</td>
    <td>Sample2c</td>
    <td>3</td>
  </tr>
  <tr>
    <td>Sample3a</td>
    <td>Sample3b</td>
    <td>Sample3c</td>
    <td>1</td>
  </tr>
  <tr>
    <td>Sample4a</td>
    <td>Sample4b</td>
    <td>Sample4c</td>
    <td>2</td>
  </tr>
</table>

As an example, all the rows that end with 1 would have a red font, end with 2 a green font, and end with 3 a black font.

Also, would it be possible to hide the "value" column?

Thanks for the help,
ChiSoxFan
 
No, I am afraid you cannot do that with CSS2. If the data is populated dynamically, you could add logic to it and output classes that would define custom colours.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top