SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: css comments

  1. #1
    SitePoint Guru
    Join Date
    Oct 2010
    Location
    Portland, Or
    Posts
    781
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    css comments

    I know that to comment out css you use /* code code code */
    but i noticed that sometime you find a php // and it seems to nulify the css code as well. at least for that one line.
    would there be issues if the coder uses // instead that the /* */ ?
    it seems it stills works.
    thx
    D

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,481
    Mentioned
    182 Post(s)
    Tagged
    6 Thread(s)
    Hi,
    Quote Originally Posted by pdxSherpa View Post
    I know that to comment out css you use /* code code code */
    but i noticed that sometime you find a php // and it seems to nulify the css code as well. at least for that one line.
    would there be issues if the coder uses // instead that the /* */ ?
    it seems it stills works.
    thx
    D
    CSS comments are as you stated /* stuff here ignored as far as css is concerned */. They are the only comments you should use.

    What I think you are experiencing is something like this:

    Code:
    //
    div{background:red}
    The rule above will not work because CSS is looking for a selector called "// div {}" and none exists. All you have done is describe a non existent element so nothing gets matched. The rule following that would match though.

    It's the same problem you get when someone duplicates a bracket in error.

    e.g.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <style>
    div { 
    background:red 
    }
    }
    p { background:green }
    </style>
    </head>
    
    <body>
    <div><p>Test</p></div>
    </body>
    </html>
    The CSS looks for a selector called "} p" and none exists so it moves on. Sometimes in Firefox this can stop any following rules working.

    That's why its important to validate the code and check for erroneous errors.


Bookmarks

Posting Permissions

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