Solved

Conditional formatting in CSS???

Posted on 2007-03-21
5
2,354 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

832 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