Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Conditional formatting in CSS???

Posted on 2007-03-21
5
Medium Priority
?
2,398 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

715 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