为什么“&lt ;! - “注释一个样式规则,但是“<! - 才不是? [英] Why does "<! --" comment out a style rule, but "<!--" does not?

查看:143
本文介绍了为什么“&lt ;! - “注释一个样式规则,但是“<! - 才不是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

轻易就可以了。我只是在学习HTML。



加入 http://www.w3.org/TR/html-markup/syntax.html#comments 以及我见过的许多其他网站,例如 http://www.w3schools.com/tags/tag_comment.asp



他们说HTML评论是与下一个破折号之间没有空格的<! - text - > b
$ b

然而,我在下面显示,只有当我写<! - test - > 是内部的东西实际上被忽略。注意<! -

之间添加的空格

这里是HTML代码

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

现在运行它之前,表格是否有边框?



如果text / css中的内容真的被注释掉,那么表格不应该有边框,对吧?但它是。我试过这个在chrome版本24.0.1312.52下linux薄荷14,还火狐18.0



现在当我改变到

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

注意额外的空间。然后,表格显示没有预期的边框。当我实际删除整行时也是如此:

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

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

< / body>
< / html>

问题:注释 ! - text - > 或者是< ;! - text - >

解决方案

CSS不接受HTML <! - comment here - > 注释。相反,CSS使用 / * comment * / 来注释行。试试。


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

解决方案

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

这篇关于为什么“&lt ;! - “注释一个样式规则,但是“&lt;! - 才不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆