CSS is getting apply despite of comments??
I have seen Commented CSS in my P开发者_JAVA技巧HP page enclosed within <!-- -->
like
<style type="text/css">
<!--
body { }
...
-->
</style>
when I was optimizing my code then I deleted those commented CSS code from my page,
but after deleting, layout of that page has been disturbed.
when I again paste those commented CSS , it was working fine??
please tell me the reason and how does it possible that CSS is applying despite of comments
Because you're using the wrong comments syntax, you should be using: /* ... */
to comment out CSS, the <!-- ... -->
is html comment syntax; and once you're inside of the style
element html is itself invalid and can, therefore, be handled by the browser as it sees fit.
Therefore you may want to try:
<style type="text/css">
/*
body { }
...
*/
</style>
It's worth noting that, like html, there is no single-line comment syntax, which in JavaScript for example would be anything following //
.
Some further information: CSS - smarter code comments
HTML comments don't apply to CSS. You need to use CSS-style comments:
<style type="text/css">
<!--
/* This is a comment. The following rule will be applied. */
body { }
/* This rule has been commented out
h1 { }
*/
-->
</style>
Those (<!-- xx -->
) are HTML comments, which does NOT affect CSS.
To comment out CSS, use /* xx */
精彩评论