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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS Style w/o Tag Name Not Recognized 2

Status
Not open for further replies.

xyzuser

Technical User
Aug 13, 2008
96
0
0
US
This is a CSS I have:
Code:
.Change
{font-weight:bold;
color:blue; font-size:19px;
font-family:"Typo Upright BT", "Times New Roman", serif;  border-style:none; PADDING-BOTTOM:  0pt;}
I am using it here:
Code:
<P class=Normal align=Left><A href="/MyPage10.html"><IMG src="images/Page10.gif"
border="0" alt="Go to Page10" height="40"></a><br>
<span class=Change>Page Added 1/15/09</span></p>

The CSS is not being recognized. I do not get any of the style settings in the span . But, as a test, I added the selector p to the CSS and changed where I use it to be in the p
Code:
 p.Change {font-weight:bold;...
and
Code:
<P class=Change align=Left><A href="/MyPage10.html">...

Now, once the tage name is specified in the selector, I do get the blue color. But I still don't get the right font nor the right font size.

What is wrong with my CSS and /or how I am using it? If I would get the rest of the CSS using it as p changes I would keep it that way and not bother with the span.
Thanks
 
OK - I figured it out. span requires quotation marks around the class name, whereas P doesn't need quotation marks around the class name (and in fact I never use quotation marks there). I put in the quotation marks and the span works correctly now.

Wouldn't it be nice if it was consistent so that less experienced people (like myself) could avoid these mistakes.

 
Actually, if you code to standards, all element attribute values require quotation marks, just like all element names and attribute names need to be lower case. Following these standards can help you develop a style where such mistakes do not happen.

However, your problem must've been something else, since there is no difference between a span element class with no quotes around the value and a paragraph element class with the same attributes. Something else must've triggered the solution.

Quotes around attribute values are not necessary for browsers to correctly decipher most values. However, if you're trying to apply two classes to a same element (which need to be separated by a space), the second class will not be applied, because space is also the separator for multiple attributes in an element. That is just one of the reasons where putting quotes around attribute values is absolutely needed for the code to work properly. And that is why quoting is required by standards.

[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Hi

xyzuser said:
span requires quotation marks around the class name, whereas P doesn't need quotation marks around the class name
As we saw in your previous thread ( thread215-1526363 ), the [tt]DOCTYPE[/tt] matters when you write lousy code. And I bet you experienced this behavior with Strict. The solution to avoid such unpleasant time wasting is to write standard compliant code.
W3C said:
We recommend using quotation marks even when it is possible to eliminate them.
( HTML 4.01 Specification | On SGML and HTML | Attributes )

In HTML 4.01 Transitional you must quote all attribute values containing characters with special meaning.

In HTML 4.01 Strict and XHTML you must quote all attribute values.


Feherke.
 
Thank you (and stars) Feherke and Vragabond for your information and advice. It is appreciated.

It was actually using Transitional (with the href) where I had the problem. But I will henceforth use quotation marks for the classes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top