Warning! -Take the wrong comment type out of your stylesheets NOW (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets



Message


gorilla -> Warning! -Take the wrong comment type out of your stylesheets NOW (11/19/2003 14:23:24)

All too often I see something like this in the head of people's pages:

<style type="text/css">
<!--
css here
-->
</style>

And in external stylesheets also. In each case it is is very very wrong. - You should never use HTML comments in your style sheet.

However it is extremely wrong in embedded style sheets and is going to give a lot of people a lot of trouble in the not too distant future.

HTML COMMENTS ARE FOR HTML:

<!-- qwertyuiop -->

CSS COMMENTS ARE FOR CSS:

ONLY use css comments in style sheets.

/* This is the only right way to comment CSS */

Anything else is sematically and syntactically incorrect and a said above will give you problems in the not too distant future.

Why?

1. Putting in HTML comments was an early hack to prevent non css aware browsers from trying to parse the css.

2. It is not now, never was, and never will be part of the standard.

3. Some gecko based UAs are starting to "silently remove" anything between html comments.

3a: Yes I'm serious, we're currently alpha testing several UAs that do this.

4. The implications should be very obvious.

To repeat your css should look like this:

<style type="text/css">

css here

</style>


and not like this:

<style type="text/css">
<!--
css here
-->
</style>

Edited: to more clearly reflect an implicit point made by c1sissy in posting below.

jb




c1sissy -> RE: Warning! -Take the wrong comment type out of your stylesheets NOW (11/19/2003 16:10:52)

quote:

ORIGINAL: gorilla

All too often I see something like this:

<style type="text/css">
<!--
css here
-->
</style>

In people's stylesheets. This is very very wrong. - Never use HTML comments in your style sheet.

HTML COMMENT:

<!-- qwertyuiop -->

ONLY use css comments in style sheets.

CSS COMMENT:

/* This is the only right way to comment CSS */

Why?

1. Putting in HTML comments was an early hack to prevent non css aware browsers from trying to parse the css.

2. It is not now, never was, and never will be part of the standard.

3. Some gecko based UAs are starting to "silently remove" anything between html comments.

3a: Yes I'm serious, we're currently alpha testing several UAs that do this.

4. The implications should be very obvious.

To repeat your css should look like this:

<style type="text/css">

css here

</style>


and not like this:

<style type="text/css">
<!--
css here
-->
</style>


This is very interesting to read.

If we are still working with older browsers that won't recognize the css and will possibly print our styles, then what do we do to eliminate this? (dont' be too hard on me, I'm only in training here[;)])

Also, if I don't put this into my homework, how do I explain to the instructor that this is not supposed to be, when all tutorials that I have read have instructed you to do so?




gorilla -> RE: Warning! -Take the wrong comment type out of your stylesheets NOW (11/19/2003 16:48:05)

quote:

ORIGINAL: c1sissy
This is very interesting to read.

1. If we are still working with older browsers that won't recognize the css and will possibly print our styles, then what do we do to eliminate this? (dont' be too hard on me, I'm only in training here[;)])

2. Also, if I don't put this into my homework, how do I explain to the instructor that this is not supposed to be, when all tutorials that I have read have instructed you to do so?


0. I'm going to edit my post above to reflect a point you've made by implication.

1. If you're still working with Netscape2, and IE 3.0 then you've got far bigger problems than this anyway. [;)]

1.1 - The other css nonaware browsers can safely be reckoned to be dead at this point. except for:

1.1a - Lynx a text only browser that will ignore css anyway.

1.1b - Some versions of IE for PDAs - I think you can safely ignore this also as it also appears to be CSS unaware and is anyway not gecko based.

1.1c - Specialised browser type apps such as JAWS used by blind people.

2.0 Suggest as sweetly as you may that she download a copy of the specs from W3C and try to find where in the spec it say that html comments in css is either syntactically or (more importantly) semantically correct.

I know that's not very helpful but if that's what she's telling you then she's giving you incorrect information, a lot of people are labouring under this delusion, but it is quite simply incorrect, and in my view it behoves a teacher to make extra efforts - if we can do it ......... (Said Jesper trying to be as tactful as possible [;)] )

- Of course there's nothing to stop you doing it just to keep her happy and then taking it out as a matter of urgency once you've finished the course. (This is me slipping in to "peacekeeper mode" a few weeks before I leave on a tour of peackeeping duty. - Thanks for the practice [:)])

PS: Shirley put in a link to a posting she made that gives a good example of the right way to do it while I was typing - Thank you Shirley.

JB




Shirley -> RE: Warning! -Take the wrong comment type out of your stylesheets NOW (11/19/2003 16:55:04)

http://www.frontpagewebmaster.com/m-162155/mpage-1/key-commented/anchor/tm.htm#162155




c1sissy -> RE: Warning! -Take the wrong comment type out of your stylesheets NOW (11/19/2003 17:35:54)

quote:

2.0 Suggest as sweetly as you may that she download a copy of the specs from W3C and try to find where in the spec it say that html comments in css is either syntactically or (more importantly) semantically correct.

I know that's not very helpful but if that's what she's telling you then she's giving you incorrect information, a lot of people are labouring under this delusion, but it is quite simply incorrect, and in my view it behoves a teacher to make extra efforts - if we can do it ......... (Said Jesper trying to be as tactful as possible )

- Of course there's nothing to stop you doing it just to keep her happy and then taking it out as a matter of urgency once you've finished the course. (This is me slipping in to "peacekeeper mode" a few weeks before I leave on a tour of peackeeping duty. - Thanks for the practice )

PS: Shirley put in a link to a posting she made that gives a good example of the right way to do it while I was typing - Thank you Shirley.

JB

I could do the homework in an a and b type thingie, lol.

In regards to what Shirley posted. Isn't this a different means of commenting?

The one that Shirley has referred to is the one that you would use for commenting OUT code? Say I'm trying something not sure if I like it, but don't want to get rid of it while I try something else, I would just comment it out, and if I decide that this is what I want I would just remove the comments? As well as the reason that is mentioned in the thread that Shirley posted.

The commenting out that is referred to in your posting is to keep other browsers that aren't css compatible from seeing the styles?

Don't mean to be a stubborn student here, but lol, just want it all to make sense[;)]

<edit>
http://www.w3.org/TR/2003/WD-CSS21-20030915/syndata.html#comments
How does this apply to using or not using? and is this standard or not standard?</edit>




gorilla -> RE: Warning! -Take the wrong comment type out of your stylesheets NOW (11/19/2003 18:33:57)

quote:

ORIGINAL: c1sissy

1. In regards to what Shirley posted. Isn't this a different means of commenting?

2. The one that Shirley has referred to is the one that you would use for commenting OUT code? Say I'm trying something not sure if I like it, but don't want to get rid of it while I try something else, I would just comment it out, and if I decide that this is what I want I would just remove the comments? As well as the reason that is mentioned in the thread that Shirley posted.

3. The commenting out that is referred to in your posting is to keep other browsers that aren't css compatible from seeing the styles?

Don't mean to be a stubborn student here, but lol, just want it all to make sense[;)]

<edit>
4. http://www.w3.org/TR/2003/WD-CSS21-20030915/syndata.html#comments
How does this apply to using or not using? and is this standard or not standard?</edit>


1. No, it is the correct way of commenting in

a - an external css file.

b - an stylesheet embedded in the document.

2. Yes, and that is indeed a very good use for it. But it is by no means limited to that. Comments are there to for example, help you remember which bit of the file refers to which selectors. EG:

/* Start of left navigation styles */

stuff

/*End of left navigation styles */

/* Start of right navigation styles */

stuff

/*End of rigth navigation styles */

/* Start of main content styles */

stuff

/*End of main content styles */

/* Start of hacks to cope with broken box model in ie5.5 styles */

stuff

/* End of hacks to cope with broken box model in ie5.5 styles */

and so on. Comments are just that. any text between this:

/*

and this

*/ will simply be ignored by the UA.

IOW you can put in anything you like upto and including the collected works of William Shakespeare and as long as they are between /* and */ they'll be ignored.

3. Yes, they are html comments. HOwever as I have clarified further below with a quote from the relevant document for anything above html3.2 it is sematically and syntactically incorrect to use it. Forthcoming gecko based UAs can (and will) "silently remove" anything between html comments. with a very unpleasant effect upon your page. - This is per spec btw.

4. Key paragraph is:

quote:

CSS also allows the SGML comment delimiters ("<!--" and "-->") in certain places, 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.0 specification ([HTML40]) for more information


Emphasis added by me. - So not part of html 4.0 bis.

5. Be as stubborn as you like it needs to make sense. [:D]

6. That page btw is one of the more important ones in the spec.

jb




c1sissy -> RE: Warning! -Take the wrong comment type out of your stylesheets NOW (11/19/2003 19:24:55)

quote:

2. Yes, and that is indeed a very good use for it. But it is by no means limited to that. Comments are there to for example, help you remember which bit of the file refers to which selectors. EG:

/* Start of left navigation styles */

stuff

/*End of left navigation styles */

/* Start of right navigation styles */

stuff

/*End of rigth navigation styles */

/* Start of main content styles */

stuff

/*End of main content styles */

/* Start of hacks to cope with broken box model in ie5.5 styles */

stuff

/* End of hacks to cope with broken box model in ie5.5 styles */

and so on. Comments are just that. any text between this:

/*

and this

*/ will simply be ignored by the UA.


Silly me, lol, I realize that you can use this commenting for other things as well. I myself use this to remind myself of the colors that I am using etc...

As for the <!-- comment--> this is for only below a certain html. Not for use with xhtml and html 4.0? Therefore, if you are using the most current coding then you should not use the previous mentioned comment. wheww. what a mouth full.[;)]
<edit> hoping that I have this correct!</edit>




gorilla -> RE: Warning! -Take the wrong comment type out of your stylesheets NOW (11/19/2003 19:42:12)

quote:

ORIGINAL: c1sissy


As for the <!-- comment--> this is for only below a certain html. Not for use with xhtml and html 4.0? Therefore, if you are using the most current coding then you should not use the previous mentioned comment. wheww. what a mouth full.[;)]
<edit> hoping that I have this correct!</edit>


correct - go to the top of class [:)]

goodnight.

JB - 1:40 AM




c1sissy -> RE: Warning! -Take the wrong comment type out of your stylesheets NOW (11/19/2003 19:43:47)

quote:

ORIGINAL: gorilla

quote:

ORIGINAL: c1sissy


As for the <!-- comment--> this is for only below a certain html. Not for use with xhtml and html 4.0? Therefore, if you are using the most current coding then you should not use the previous mentioned comment. wheww. what a mouth full.[;)]
<edit> hoping that I have this correct!</edit>


correct - go to the top of class [:)]

goodnight.

JB - 1:40 AM


Thank you #1 instructor![;)]

Sweet dreams!




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625