鱼C论坛

 找回密码
 立即注册
查看: 1362|回复: 2

[已解决]想问一下大佬,为什么这段代码明明注释掉了,但是为什么还是跑起来了

[复制链接]
发表于 2023-3-17 15:04:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 猪头少年.zm 于 2023-3-17 15:07 编辑

本人纯属web开发的萌新,想问一下为什么代码注释掉和删除掉的结果为什么不一样,明明注释的时候字体颜色已经改变了啊。

发不了图片,555~

注释掉的代码是这个
  1. <!--thead th{                                                                              
  2.                 background:grey;
  3.                 color:white;
  4.         }
  5.         tbody th{
  6.                 background:lightgrey;
  7.                 color:white;
  8.         }-->
复制代码

但是运行出来的结果却和原来的结果一样,表格的颜色还是会变,为什么呢?

但是删除掉就不会再变了
  1. <doctype html>
  2. <html>
  3.         <head>
  4.         <title>这是一个表单</title>
  5.         <meta charset = "utf-8">
  6.         <meta name ="viewpoint" content = "width = device-width initial-scale = 1.0">
  7.         <meta name = "author" content = "为什么我总是学渣贡献">
  8.         <meta name = "discription" contenr = "genshin">
  9.         <style>
  10.         body{
  11.         background-image:URL("../相册/原神图片/海灯节.png")
  12.         }
  13.         </style>
  14.         <style>
  15.         table{
  16.                 border:1px solid black;
  17.                 border-collapse:collapse;
  18.         }
  19.         <!--thead th{                                                                              
  20.                 background:grey;
  21.                 color:white;
  22.         }
  23.         tbody th{
  24.                 background:lightgrey;
  25.                 color:white;
  26.         }-->
  27.         th{
  28.                 border:1px solid black;
  29.                 padding:5px;
  30.         }
  31.         td{
  32.                 border:1px solid black;
  33.         }
  34.         </style>
  35.         </head>
  36.         <body>
  37.         <table>
  38.                                 <caption>SCU Fractional line over the years</caption>
  39.                 <tr>
  40.                                 <th>   </th>
  41.                                 <th>English</th>
  42.                                 <th>Math</th>
  43.                                 <th>Politics</th>
  44.                                 <th>Major</th>
  45.                 </tr>
  46.                
  47.                 <tr>
  48.                                 <th>2021Mark</th>
  49.                                 <td> 67 </td>
  50.                                 <td> 89 </td>
  51.                                 <td> 70 </td>
  52.                                 <td> 100 </td>
  53.                 </tr>
  54.                
  55.                 <tr>
  56.                                 <th>2022Mark</th>
  57.                                 <td> 69 </td>
  58.                                 <td> 83 </td>
  59.                                 <td> 64 </td>
  60.                                 <td> 120 </td>
  61.                 </tr>
  62.         </table>
  63.         </body>
  64. </html>
复制代码
最佳答案
2023-3-17 15:17:02
这个注释不生效是因为你使用了 HTML 注释符号 <!-- 和 -->,而不是 CSS 注释符号 /* 和 */。

在 CSS 中,应该使用 /* 和 */ 进行注释。

下面是修正后的代码:

  1. <doctype html>
  2. <html>
  3.         <head>
  4.         <title>这是一个表单</title>
  5.         <meta charset = "utf-8">
  6.         <meta name ="viewpoint" content = "width = device-width initial-scale = 1.0">
  7.         <meta name = "author" content = "为什么我总是学渣贡献">
  8.         <meta name = "discription" contenr = "genshin">
  9.         <style>
  10.         body{
  11.         background-image:URL("../相册/原神图片/海灯节.png")
  12.         }
  13.         </style>
  14.         <style>
  15.         table{
  16.                 border:1px solid black;
  17.                 border-collapse:collapse;
  18.         }
  19.         /*thead th{                                                                              
  20.                 background:grey;
  21.                 color:white;
  22.         }
  23.         tbody th{
  24.                 background:lightgrey;
  25.                 color:white;
  26.         }*/
  27.         th{
  28.                 border:1px solid black;
  29.                 padding:5px;
  30.         }
  31.         td{
  32.                 border:1px solid black;
  33.         }
  34.         </style>
  35.         </head>
  36.         <body>
  37.         <table>
  38.                                 <caption>SCU Fractional line over the years</caption>
  39.                 <tr>
  40.                                 <th>   </th>
  41.                                 <th>English</th>
  42.                                 <th>Math</th>
  43.                                 <th>Politics</th>
  44.                                 <th>Major</th>
  45.                 </tr>
  46.                
  47.                 <tr>
  48.                                 <th>2021Mark</th>
  49.                                 <td> 67 </td>
  50.                                 <td> 89 </td>
  51.                                 <td> 70 </td>
  52.                                 <td> 100 </td>
  53.                 </tr>
  54.                
  55.                 <tr>
  56.                                 <th>2022Mark</th>
  57.                                 <td> 69 </td>
  58.                                 <td> 83 </td>
  59.                                 <td> 64 </td>
  60.                                 <td> 120 </td>
  61.                 </tr>
  62.         </table>
  63.         </body>
  64. </html>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-3-17 15:17:02 | 显示全部楼层    本楼为最佳答案   
这个注释不生效是因为你使用了 HTML 注释符号 <!-- 和 -->,而不是 CSS 注释符号 /* 和 */。

在 CSS 中,应该使用 /* 和 */ 进行注释。

下面是修正后的代码:

  1. <doctype html>
  2. <html>
  3.         <head>
  4.         <title>这是一个表单</title>
  5.         <meta charset = "utf-8">
  6.         <meta name ="viewpoint" content = "width = device-width initial-scale = 1.0">
  7.         <meta name = "author" content = "为什么我总是学渣贡献">
  8.         <meta name = "discription" contenr = "genshin">
  9.         <style>
  10.         body{
  11.         background-image:URL("../相册/原神图片/海灯节.png")
  12.         }
  13.         </style>
  14.         <style>
  15.         table{
  16.                 border:1px solid black;
  17.                 border-collapse:collapse;
  18.         }
  19.         /*thead th{                                                                              
  20.                 background:grey;
  21.                 color:white;
  22.         }
  23.         tbody th{
  24.                 background:lightgrey;
  25.                 color:white;
  26.         }*/
  27.         th{
  28.                 border:1px solid black;
  29.                 padding:5px;
  30.         }
  31.         td{
  32.                 border:1px solid black;
  33.         }
  34.         </style>
  35.         </head>
  36.         <body>
  37.         <table>
  38.                                 <caption>SCU Fractional line over the years</caption>
  39.                 <tr>
  40.                                 <th>   </th>
  41.                                 <th>English</th>
  42.                                 <th>Math</th>
  43.                                 <th>Politics</th>
  44.                                 <th>Major</th>
  45.                 </tr>
  46.                
  47.                 <tr>
  48.                                 <th>2021Mark</th>
  49.                                 <td> 67 </td>
  50.                                 <td> 89 </td>
  51.                                 <td> 70 </td>
  52.                                 <td> 100 </td>
  53.                 </tr>
  54.                
  55.                 <tr>
  56.                                 <th>2022Mark</th>
  57.                                 <td> 69 </td>
  58.                                 <td> 83 </td>
  59.                                 <td> 64 </td>
  60.                                 <td> 120 </td>
  61.                 </tr>
  62.         </table>
  63.         </body>
  64. </html>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2023-3-17 16:01:15 | 显示全部楼层
isdkz 发表于 2023-3-17 15:17
这个注释不生效是因为你使用了 HTML 注释符号 ,而不是 CSS 注释符号 /* 和 */。

在 CSS 中,应该使用 / ...

谢谢大佬的帮助,我忘记了这些是CSS的内容了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-4 21:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表