Solved

Space in Class Name

Posted on 2004-10-01
9
267 Views
Last Modified: 2012-05-05
I have an asp page that displays some text which is formatted by a stylesheet. The colour of the text box depends on the text itself.

For example, the information displayed is a risk. If the risk is 'None', the box is white, if it is 'High', the box is red, etc.

The class is determined programmatically, according to the actual risk. In the stylesheet I have a class called 'None', another called 'High', etc.

The problem I have is that one of the risks is 'No Risk' which obviously has a space in it. The text MUST say 'No Risk' so the solution is not to have text with no space in.

How do I create a class in my stylesheet called No Risk? If I type it literally, with the space, it doesn't recognise it.

I have a procedure that selects the Risk from a database table. The asp page has the following line to set the class:

Response.Write "<td class=" & chr(34) & Replace((rs.Fields.Item("risk").Value) , " ", "") &"2" & chr(34) & ">" & (rs.Fields.Item("risk").Value) & "</td>"

Any help would be very gratefully receive it as I am rapidly running out of hair!

Thank you.
0
Comment
Question by:FingersLily
9 Comments
 
LVL 5

Expert Comment

by:php-webdesign
Comment Utility
maybe try adding a "_" in place of the space

since i am no asp guy, i don't know the funtion. But use "replace" or something to change this "_" in "&nbsp;"

OR (not sure if it works)

remove the " " with "&nbsp;"
0
 
LVL 14

Accepted Solution

by:
dfu23 earned 125 total points
Comment Utility
If the value coming back from s.Fields.Item("risk") is "No Risk" then the replace you are doing should result in "NoRisk" ... right? Well, then you add a "2" to that, so "NoRisk2"?

In this case make a CSS class like this

.NoRisk2 {
    /* Add rules as needed */
}

And maybe use this ASP code too:

Response.Write "<td class=""" & Replace(rs.Fields.Item("risk").Value), " ", "") & "2"">" & rs.Fields.Item("risk").Value & "</td>"
0
 

Author Comment

by:FingersLily
Comment Utility
Thanks for the replies.

Sorry, the code I posted was after I'd tried a few remedies.
I put the 2 on the end so I could leave the original alone.

As you said dfu23, I created a class named NoRisk2 in my stylesheet but it still wasn't working.

I've actually solved the problem now in a roundabout way by testing for the value of risk first.

If risk = 'No Risk' then class = 'NoRisk'
else
code as before.

Thanks for your help although I'm still unsure why your suggestion doesn't work.
0
 
LVL 3

Expert Comment

by:PaulPosition
Comment Utility
I'm pretty sure you'd be better following 'php-webdesign's advice which is to replace spaces with the underscore character. I'd even go further than that and instead of testing for 'risk' or 'no risk' I'd simply search&replace spaces for '_' in every link.

Why? Because more than 'risk' and 'no risk' , there may be a day when you need, for example, 'important' and 'not important'. Same problem. If you already coded it so it replaces spaces with underscores, there's not much you'd need to do. With your current solution, you'd need to add a second 'if()' then who knows, a third one, etc..

Just my thoughts anyway, sorry I have no .asp code to show up.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:PaulPosition
Comment Utility
(oh, as for spaces in class names like class="no risk" well if I'm not mistaken, it assigns both the class 'no' and the class 'risk' to the thing. see http://www.w3.org/TR/SVG/styling.html#ClassAttribute  )

Could be usefull, but not exactly what you're looking for, is it?
0
 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
As addition to PaulPosition, even better would be to replace all kinds of whitespaces into underscores and possible even every multiple underscores into one single underscore, just in case someone goes wrong and a type like "no    risk" is entered or someting.

Regards -r-
0
 
LVL 11

Expert Comment

by:neester
Comment Utility
Yeah, if you have a classname with a space, it will interpret them as 2 seperate Classes....


Response.Write "<td class=" &  (rs.Fields.Item("risk").Value)  &  ">" & (rs.Fields.Item("risk").Value) & "</td>"

If you use that code...
From what you said, the class could be:

High or None...

therefore, add 2 classes:


td.High {background-color: #5A5;}
and
td.None {background-color: #F00;}
0
 
LVL 18

Expert Comment

by:arantius
Comment Utility
A CSS class name can not have a space in it.  A space in the class="thing otherthing" is the way to assign more than one class to an element.
The only way that will work is to change the phrase "No Risk" to something without a space in it when you are placing it in your class="" attribute.
0
 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
I guess the thread starter has already got that idea going arantius, as it was already mentioned a couple of times, in my screen resolution at least.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Unordered lists (HTML ul tags) are very handy to create menus of all types, shapes and sizes.  All it takes is a little knowledge of CSS and the possibilities are endless. First off, you should know the general format for menus created using the …
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now