Jump to content

CSS inside a comment


SandySynaptik

Recommended Posts

I am well known about comments tags in CSS and know that everything kept inside it is ignored by the browser But, see below:

<style type="text/css"><!--@import "http://www.example.com/css/example.css";--></style>
How is browser importing the CSS. It shouldn't do so. Am I right?
Link to comment
Share on other sites

Originally (1992) HTML did not use CSS or JavaScript. After a few years, CSS and scripting were added to the specification. This meant that new browsers understood them, but older browsers did not. The result was that everything inside the style or script tags was printed in the document as plain text.To avoid that, you could put comment tags inside your style/script tags. Browsers that did not understand CSS would ignore everything inside the comment tags. Browsers that did understand CSS would IGNORE the comment tags. This was a special way of handling comment tags, not the same way that comment tags are handled outside style or script tags.Today, ALL browsers understand CSS, so they all ignore the comment tags inside style and script sections. Because the comment tags are ignored, the content is read and interpreted just as if it were not there.This also means that today, comment tags in style or script sections are NEVER necessary. They have not been necessary for about 10 years. There is no reason to use them. Experienced developers NEVER put comment tags in their <style> or <script> tags. It's not "wrong" to use them. But they serve no useful purpose.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...