猪头少年.zm 发表于 2023-3-17 15:04:06

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

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

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

发不了图片,555~

注释掉的代码是这个
<!--thead th{                                                                              
                background:grey;
                color:white;
        }
        tbody th{
                background:lightgrey;
                color:white;
        }-->
但是运行出来的结果却和原来的结果一样,表格的颜色还是会变,为什么呢?

但是删除掉就不会再变了
<doctype html>
<html>
        <head>
        <title>这是一个表单</title>
        <meta charset = "utf-8">
        <meta name ="viewpoint" content = "width = device-width initial-scale = 1.0">
        <meta name = "author" content = "为什么我总是学渣贡献">
        <meta name = "discription" contenr = "genshin">
        <style>
        body{
        background-image:URL("../相册/原神图片/海灯节.png")
        }
        </style>
        <style>
        table{
                border:1px solid black;
                border-collapse:collapse;
        }
        <!--thead th{                                                                              
                background:grey;
                color:white;
        }
        tbody th{
                background:lightgrey;
                color:white;
        }-->
        th{
                border:1px solid black;
                padding:5px;
        }
        td{
                border:1px solid black;
        }
        </style>
        </head>
        <body>
        <table>
                                <caption>SCU Fractional line over the years</caption>
                <tr>
                                <th>   </th>
                                <th>English</th>
                                <th>Math</th>
                                <th>Politics</th>
                                <th>Major</th>
                </tr>
               
                <tr>
                                <th>2021Mark</th>
                                <td> 67 </td>
                                <td> 89 </td>
                                <td> 70 </td>
                                <td> 100 </td>
                </tr>
               
                <tr>
                                <th>2022Mark</th>
                                <td> 69 </td>
                                <td> 83 </td>
                                <td> 64 </td>
                                <td> 120 </td>
                </tr>
        </table>
        </body>
</html>

isdkz 发表于 2023-3-17 15:17:02

这个注释不生效是因为你使用了 HTML 注释符号 <!-- 和 -->,而不是 CSS 注释符号 /* 和 */。

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

下面是修正后的代码:

<doctype html>
<html>
      <head>
      <title>这是一个表单</title>
      <meta charset = "utf-8">
      <meta name ="viewpoint" content = "width = device-width initial-scale = 1.0">
      <meta name = "author" content = "为什么我总是学渣贡献">
      <meta name = "discription" contenr = "genshin">
      <style>
      body{
      background-image:URL("../相册/原神图片/海灯节.png")
      }
      </style>
      <style>
      table{
                border:1px solid black;
                border-collapse:collapse;
      }
      /*thead th{                                                                              
                background:grey;
                color:white;
      }
      tbody th{
                background:lightgrey;
                color:white;
      }*/
      th{
                border:1px solid black;
                padding:5px;
      }
      td{
                border:1px solid black;
      }
      </style>
      </head>
      <body>
      <table>
                              <caption>SCU Fractional line over the years</caption>
                <tr>
                              <th>   </th>
                              <th>English</th>
                              <th>Math</th>
                              <th>Politics</th>
                              <th>Major</th>
                </tr>
               
                <tr>
                              <th>2021Mark</th>
                              <td> 67 </td>
                              <td> 89 </td>
                              <td> 70 </td>
                              <td> 100 </td>
                </tr>
               
                <tr>
                              <th>2022Mark</th>
                              <td> 69 </td>
                              <td> 83 </td>
                              <td> 64 </td>
                              <td> 120 </td>
                </tr>
      </table>
      </body>
</html>

猪头少年.zm 发表于 2023-3-17 16:01:15

isdkz 发表于 2023-3-17 15:17
这个注释不生效是因为你使用了 HTML 注释符号 ,而不是 CSS 注释符号 /* 和 */。

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

谢谢大佬的帮助,我忘记了这些是CSS的内容了
页: [1]
查看完整版本: 想问一下大佬,为什么这段代码明明注释掉了,但是为什么还是跑起来了