Why are there style sheets in the comments?

<style type="text/css">
<!--
.style1 {
    color: #666666;
    font-weight: bold;
}
.style8 {font-size: 12px; color: #333333; }
.style9 {
    font-size: 12px;
    font-weight: bold;
    color: #FFFFFF;
}
.style12 {font-size: 12px; font-weight: bold; color: #666666; }
.style13 {font-size: 12px; font-weight: bold; color: #0066FF; }
.style14 {
    color: #0043A8;
    font-size: 16px;
}
.style15 {color: #FFFFFF}
.style16 {color: #990000}
.style18 {color: #990000; font-size: 12px; }
.style20 {font-size: 12px; font-weight: bold; color: #575757; }
-->
</style>

      

Above the stylesheet is wrapped in the <!-- -->

html comments tag . What for? I cannot get a valid explanation for this; some tutorials do this, while some don't (like http://www.w3schools.com/css/css_howto.asp which I think is a very credible link)

+3


source to share


5 answers


which is not a comment ... this is a way to hide such a text block from the old browser parser (mostly IE6-)

Just like using CDATA in a tag <script>

... to protect bad parsing data from really weird engines (mostly IE) :)

although the correct way would be to use:

for styles

<style type="text/css">
/*<![CDATA[*/
    body { color: yellow; }     
/*]]>*/
</style>

      

for scripts



<script type="text/javascript">
//<![CDATA[
    $(function() { ... });
//]]>
</script>

      

using CDATA

in both cases is the correct and safe way , comment is just a trick to achieve the same end result.


Now, referring to yours , I think this is a very valid link , when you point to W3Schools, look at this:

http://w3fools.com/

+6


source


This is an outdated method of hiding content from browsers older than the standard that introduced the <style>

or tags <script>

.

There is no valid use for such a habit, and in fact it will cause more problems than it fixes.



Unless you are designing a site for people living in 1990 (like the editors at w3schools) ... don't!

+2


source


This is to avoid displaying the script content in some (old) browsers that are not aware of the markup <style>

. See this .

+1


source


This is a hack for older browsers that don't support the CSS / style tag ... See http://www.w3.org/TR/html4/present/styles.html#h-14.5

+1


source


Several browsers treat codes non-HTML

as plain text. This comment is used to indicate to the browser when the code is being commented out, so it browsers

will not display it as html output.

0


source







All Articles