Solved

Conditional formatting in CSS???

Posted on 2007-03-21
5
2,368 Views
Last Modified: 2012-06-27
Does anyone know if it is possible to implement conditional formatting in CSS?

I have a HTML table of numeric data generated by an ASP script. If a number is a negative value I want it to appear in red, otherwise black. I can do this easily in ASP, but would like to do it in CSS (if it’s possible) to keep the style completely separate from the ASP page.

Any insights are much appreciated.

Many Thanks
0
Comment
Question by:inghfs
  • 2
  • 2
5 Comments
 
LVL 30

Expert Comment

by:VirusMinus
ID: 18763021
CSS cannot read the content on your page and decide to format it based on criteria like that.

CSS is applied client side *after* your page has already been generated server side by the ASP.

the way i would do it is, in ASP while looping to draw the table rows and cells, check if the number is negative and then draw the cell containing the negative number with a class.

eg.

<%
loop .. criteria..
...
...
if number < 0 then
response.write "<td class=""negative"">" & number & "</td>"
else
response.write "<td>" & number & "</td>"
end if
...
...
end loop
%>

Now in your CSS, define this class as follows:

.negative{color:red;}
0
 

Author Comment

by:inghfs
ID: 18763152
Yes this is the way I did it, just wanted to verify there wasn’t an easier way on the CSS side.

Many Thanks for the help.
0
 
LVL 30

Accepted Solution

by:
VirusMinus earned 500 total points
ID: 18763284
you're welcome :) just one thing though..i see you're fairly new here, and may not understand the grading system clearly.

just coz something can't be done, or someone confirms what you already knew, or proves that what you thought of already is the best way, it doesn't mean you grade a B or a C. You're grading history is looking pretty scary with Bs and Cs.

Giving a higher grade does not cost you any extra points, but reflects on us experts capability to provide quality answers. and also that you value our voluntary time in helping others.

Experts view your grading history often and if they see a lot of B's and C's, they would be hesitant in helping you.

I recommend reading the grading guidelines to help you grade fairly. http://www.experts-exchange.com/help.jsp#hi55

quote :
"Grading at Experts Exchange is not like school. It's more like the "10-point Must" system in professional boxing; in other words, an answer is worth an A, unless it doesn't resolve your issue. If it requires you to do a little more research, or figure out one more piece of code, then it's worth a B. If you think it's not worth a B, the custom is to offer the Experts an opportunity to earn a better grade."

And if you ever wish to change any grade you've awarded incorrectly or by mistake, just post a 0 point question in Community Support Zone requesting so with a link to the question.
0
 

Author Comment

by:inghfs
ID: 18764054
Appreciate the advice; I have posted the amendment in the Community Support Zone.

Many Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question