Css 简明教程

CSS - Comments

在 CSS 中, comments 可用于在样式表中添加说明性注释或注解,且不会被网络浏览器解释为样式指令。

In CSS, comments are useful in adding explanatory notes or annotations within your stylesheet that are not interpreted as styling instructions by the web browser.

Syntax

/* This is a comment */
p {
  color: red; /* Set text color to red */
}

CSS 注释旨在供开发人员使用,并且在渲染网页时会被浏览器忽略。它们在文档、调试等方面很有用。

CSS comments are intended for the benefit of developers and are ignored by the browser when rendering a web page. They are useful in documentation, debugging, etc.

Types of CSS Comments

在 CSS 中,创建注释主要有两种方法:

In CSS, there are two main ways to create comments:

  1. Single-line Comments: * Single-line comments are created using */ to start the comment and / to end it.

  2. Multi-line Comments: * Multi-line comments allow you to add comments that span multiple lines. They are also enclosed within */ and /.

/* Single line Comment */

/*
Comment
which stretches
over multiple
lines
*/

HTML And CSS comments

在 HTML 教程中,我们了解到,HTML 中的命令定义在 <!---→ 符号之间。

In HTML tutorial we learned that, a command in HTML is defined between <!-- and -→ symbols.

Syntax

<html>
   <head>
      <style>
         /* This is a CSS Comment */
      </style>
   </head>

   <body>
      <!-- This is an html comment format -->
   </body>
</html>

Example

这是一个显示 HTML 注释和 CSS 注释格式的示例:

Here is an example showing html comment and CSS comment format:

<html>
<head>
   <style>
      /* Target all div elements */
      div {
         background-color: red; /* Set background color */
         height: 50px; /* Set the height  */
         width: 200px; /* Set the width  */
         padding: 5px; /* Set the padding  */
         border: 5px solid black; /* Set the border  */
      }
   </style>
</head>

<body>
   <!-- This is an html comment format -->
   <div>
      Styles Applied
   </div>
</body>
</html>