原文:Comment out HTML – Code Example,作者:Kolade Chris

在你的代码中添加注释是一个很好的做法,因为它使你的代码更具有可读性,易于理解。

注释不会运行,因为它们会被编译器和解释器忽略。

在这篇文章中,我将向你展示如何注释你的 HTML 代码,这样你就可以帮助自己和团队成员理解你在做什么。

如何对 HTML 代码进行注释

与其他编程语言有不同的符号来做多行和单行注释不同,在 HTML 中,你可以用同样的符号做多行和单行注释。

要注释 HTML 代码,请使用小于符号(<),后面是感叹号(!)、两个连字符(--)、注释内容、两个连字符(--)和大于符号(>)。

注释 HTML 的语法是这样的:

<!-- 注释此处 -->

你可以用它来做单行注释:

    <!-- 这是一个单行注释 -->
    <section class="about" id="about">
      <h3>Watch the Jabs</h3>
      <p>
        Our primary objective is to bring live boxing matches to fans all around
        the world
      </p>

      <h3>Its not About the Fights Alone!</h3>
      <p>
        We also air documentaries specially made for the greats, lifestyle of
        boxers, news, and more.
      </p>
    </section>

你也可以用它来做多行注释:

    <section class="about" id="about">
      <h3>Watch the Jabs</h3>
      <p>
        Our primary objective is to bring live boxing matches to fans all around
        the world
      </p>
      <!-- 这是一个多行注释 -->
      <h3>Its not About the Fights Alone!</h3>
      <p>
        We also air documentaries specially made for the greats, lifestyle of
        boxers, news, and more.
      </p>
    </section>

只要不在标签内,你也可以把注释放在任何地方:

    <section class="about" id="about">
      <h3>Watch the Jabs</h3>
      <p>
        Our primary objective is to bring live boxing matches to fans all around
        the world
      </p>
      <h3>Its not About the Fights Alone!</h3>
      <p>
        We also air
        <!-- 这是一个在文本中的注释 -->
        documentaries specially made for the greats, lifestyle of boxers, news,
        and more.
      </p>
    </section>

就是这些啦,现在你可以正确、安全地注释你的 HTML 代码了。

谢谢你阅读本文。