Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    quick question about external css file

    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...

    Code:
    <link rel="stylesheet" type="text/css" href="main.css" />
    main.css
    Code:
    <!--
    .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

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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

    Code:
    /*<![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

  • #3
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    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.

  • #5
    Regular Coder Graft-Creative's Avatar
    Join Date
    Aug 2004
    Location
    Web Designer - North East Lancashire U.K.
    Posts
    842
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    Gary

  • #6
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    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.

  • #7
    Regular Coder Graft-Creative's Avatar
    Join Date
    Aug 2004
    Location
    Web Designer - North East Lancashire U.K.
    Posts
    842
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah right, thanks Bill - I'll make a coder someday

    Gary

  • #8
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    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.

  • #9
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    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.

  • #10
    Regular Coder
    Join Date
    Jan 2005
    Location
    Essex
    Posts
    146
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Most people use comments of some sort because is organises the css better.
    Danny Hayes
    Under Construction www.hayes-design.co.uk

  • #11
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Quote Originally Posted by Graft-Creative
    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/archiv...html_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.

  • #12
    New Coder
    Join Date
    Jun 2004
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •