Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

comments

html

css

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 --> ?

like image 768
Nasser Avatar asked Jan 19 '13 03:01

Nasser


People also ask

How do you comment with style tags?

Comments in CSS can be added by using the /* tag, which is then closed off by using */ . Note: Code that is commented out is not used to style the page. This technique can be used to add both single and multi-line comments.

How do you comment a style in HTML?

The /* */ comment syntax is used for both single and multiline comments. There is no other way to specify comments in external style sheets. However, when using the <style> element, you may use <!

How do we comment out style attributes in paragraph tag?

The HTML Comment Tag Comments in HTML start with <! -- and end with --> . Don't forget the exclamation mark at the start of the tag! But you don't need to add it at the end.


1 Answers

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

like image 192
Ilan Biala Avatar answered Oct 03 '22 05:10

Ilan Biala