Search code examples
htmlcsscomments

Why does "<! --" comment out a style rule, but "<!--" does not?


Take it easy on me. I am just learning HTML.

Accroding to http://www.w3.org/TR/html-markup/syntax.html#comments and many other sites I've seen such as this http://www.w3schools.com/tags/tag_comment.asp

they say an HTML comment is <!-- text --> with no space between ! and the next dash.

Yet, I show below that only when I write <! -- test --> is the stuff inside be actually gets ignored. Notice the space added between <! and --

Here is the HTML code

<!DOCTYPE HTML>
<html>
    <head>
     <style type="text/css">   
<!-- td {border: 1px solid gray;} -->
    </style>
</head>
<body>

<table>
  <tr>   <td>      test   </td>  </tr>
</table>

</body>
</html>

Now before you run it, should the table have border or not?

If the stuff in text/css is really commented out, then the table should not have border, right? But it does. I tried this on chrome Version 24.0.1312.52 under linux mint 14, and also firefox 18.0

Now when I change the line to

 <! -- td {border: 1px solid gray;} -->

Notice the extra space now. Then the table shows up with no border as expected. The same happens when I actually delete the whole line:

<!DOCTYPE HTML>
<html>
    <head>
     <style type="text/css">   
     </style>
</head>
<body>

<table>
  <tr>   <td>      test   </td>  </tr>
</table>

</body>
</html>

question is: Is the comment <!-- text --> or is it <! -- text --> ?


Solution

  • CSS doesn't accept HTML <!-- comment here --> comments. Instead CSS uses /* comment */ to comment lines. Try that instead.