...

View Full Version : quick question about external css file



TheRoper
05-28-2005, 08:05 AM
hi all-

this is a ridiculously simple question that will probably be answered very quickly... i just wanted to know if i should use comment tags at the beginning and end of an external css file...


<link rel="stylesheet" type="text/css" href="main.css" />
main.css

<!--
.foo {
bar: blah;
}

#hello {
goodbye: blah;
}
-->

is it required, is it recommended, is it stupid, does it matter?

thanks in advance...

ps - coding to xhtml 1.0

_Aerospace_Eng_
05-28-2005, 08:10 AM
I always put them in my external stylesheets, its just like putting it as an embedded style sheet, but if you are using XHTML you should be using


/*<![CDATA[*/
.foo {
bar: blah;
}
#hello {
goodbye: blah;
}
/*//]]>*/

There is the possibility of that one browser messing up because it won't support the css, but now adays you won't run into many problems, but IF you are passing off your XHTML 1.0 as text/html then you can still use <!-- and --> as comments in the beginning or end. I showed you what you should do if you were using the content-type:application/xhtml+xml

rmedek
05-28-2005, 08:30 AM
I never use comment tags in my stylesheets. You'll be fine without them.

They were used waaaaay back when there was a good chance browsers would choke on the code in the stylesheet, but nowadays that's not really an issue.

Bill Posters
05-28-2005, 09:17 AM
Fwiw, I don't bother commenting my css (I only ever use external stylesheets).
I neither comment the @import rule(s) or the css contained within the .css file.
I conditionally serve my pages as xhtml 1.0 Strict (text/html) and as xhtml 1.1 (application/xhtml+xml) and I've not yet known a modern or even recent UA to fall over through lack of css or javascript comments, despite having a fair array of browsers - and friends with other browsers - which I use for testing throughout a site's development.
(I've never heard a peep from the tiny number of visitors to my own site who are using v4 browsers (i.e. MSIE4, NN4.5, NN4.7), despite my stats showing that they appear to be making their way round the site without issues.)

I don't profess to fully understand the use of commenting in such cases, but the impression I get is that it's mostly an issue if you're using embedded css or javascript. Seeing as though we're (now) supposed to be pushing all our css and javascript into external files, it would seem (to my limited understanding at least) that, at least to those who are using external css and js files, that commenting css and javascript in the ways mentioned above is largely a redundant practice.

Graft-Creative
05-28-2005, 09:17 AM
Am I missing some kind of *in-joke* What's all this 'Foo' stuff about?

Also Aero, what's all this CDATA about?

Sorry for souning like a noob :D

Gary

Bill Posters
05-28-2005, 09:22 AM
foo is just a generic word used to demonstrate code and used in place of a real term/element/tag/attribute.
Similar to the use of the term widget (e.g. 'Company A sells widgets'), which is regularly used as a generic, hypothetical product type when developers wish to ask about e-commerce without being too open about the specifics of their project.

Graft-Creative
05-28-2005, 09:30 AM
Ah right, thanks Bill - I'll make a coder someday ;)

Gary

JamieR
05-28-2005, 09:45 AM
I use comments in my css because it makes the code easier to find certain classes and parts etc - like form stuff, layout, a element styling etc, depening on how I arrange the code.

And I don't use the CDATA element, although I *should* probably do so.

Bill Posters
05-28-2005, 11:35 AM
That's what I meant also. I do actually use /* ... */ commenting within my css to define certain sections (and during testing), but I don't bother with the CDATA/PCDATA/SGML commenting that is mentioned earlier.

dannyhayes
05-28-2005, 12:03 PM
Most people use comments of some sort because is organises the css better.

rmedek
05-28-2005, 05:25 PM
Also Aero, what's all this CDATA about?
CDATA is essentially a comment marker for XML. Here's an article that explains it so much better than I could do:

http://www.456bereastreet.com/archive/200501/the_perils_of_using_xhtml_properly/

It's somewhere towards the middle, but the whole article is a great read.

BTW, dannyhayes and weazel, we're not talking about comments within CSS (/* comment */), we're talking about comments that prevent a browser trying to parse it as (X)HTML (i.e., <style type="text/css"><!-- stylesheet --></style>). If you call your stylesheet externally then you're safe, and don't really need to use them.

TheRoper
05-29-2005, 06:25 AM
oh man! i didn't think i'd get 10 replies on this, but it appears to be a topic of discussion... many different views on this i see... well, i think i'm just gonna take 'em out, thank you all for your replies...

take care,
TheRoper



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum