views:

361

answers:

6

Is there a good reason for this? Lame question, but I just wondered if there was a reason why.

+12  A: 

The syntax for comments in CSS is: /* comment here */

The // is not a valid syntax. I guess this allows CSS to work correctly when stripped from whitespace and new line characters during minification.

Daniel Vassallo
+1 for mentioning minification
Chad
@Daniel That seems like a really good reason for @jbail's answer above.
leeand00
Wait a minute though...you can minify Javascript and it supports the // method of commenting...*scratches head*..the js minifiers remove the comments...
leeand00
@leeand00 You can specify the end of line with a semi-colon though. If you have your semi colon insertion wrong, it will break when minified.
alex
A: 

Because the CSS language is defined so.

Tomas Lycken
+1  A: 

Different languages have different specifications with different functionality. In another language you may have comments that start with # instead of //.

See the specification.

4.1.9 Comments

Comments begin with the characters /* and end with the characters */. They may occur anywhere between tokens, and their contents have no influence on the rendering. Comments may not be nested.

CSS also allows the SGML comment delimiters (<!-- and -->) in certain places defined by the grammar, but they do not delimit CSS comments. They are permitted so that style rules appearing in an HTML source document (in the STYLE element) may be hidden from pre-HTML 3.2 user agents. See the HTML 4 specification ([HTML4]) for more information.

Note: There is no mention of comments that begin with 2 slashes and end at the line break. So that's why it's not supported.

Brian R. Bondy
+29  A: 

Because the specification allows for /**/ but not // :)

Seriously, though, CSS treats newlines like all other whitespace, and would not be able to determine the end of the comment without a terminating delimiter.

jball
+1 for mentioning the rationale. I had never considered that the `//` comment in C++ was an exception to 'whitespace neutrality'
egrunin
Now that's a good answer.
leeand00
Tagalong: `//` comments in C outside of functions can cause serious compiler puke-age depending on your compiler.
rlb.usa
I'm not sure why this prevented the use of '//' comments. Most languages provide some exception to 'whitespace neutrality' and I don't see any major downside.
Kevin Sylvestre
@Kevin I could agree, but then I think of all the cases I've seen a xsl file end up with the entire thing on a single line. It seems alot of tools(maybe less now that they've matured more) used to discard your whitespace/returns and spit everything out on one line.
AaronLS
@Aaron Good point. I forgot about the huge movement to compress all web assets.
Kevin Sylvestre
+6  A: 

Because /* */ is the style that is defined for comments in CSS.

There are a lot of other ways to write comments in other environments that doesn't work in CSS, like:

//

<!-- -->

--

'

REM

{ }

;

#

Guffa
+1 for snarky response ;)
Nate Bross
@Nate: Just trying to widen the perspective... @downvoter: If you don't explain what it is that you don't like, it's completely pointless.
Guffa
@Guffa +1, one of the many reasons I feel that down-votes should be both *owned* and *explained* (I don't *care* -so much- if someone down-votes my answers/questions, so long as they give a reason to explain *why*).
David Thomas
A: 

If you want this style of comment (and a variety of other useful features that should have been in the CSS specification), try using a LESS CSS.

Kevin Sylvestre
I would say that the possibility to use `//` as comment is not a reason to start using `LESS CSS`. But it looks like it has a lot of other useful features that would be very good reasons for using it..
awe