创建 HTML

  • 使用 <body> 标签并在 <h1> 中添加一些内容。
<!DOCTYPE html>
<html>
  <head>
    <title>文档的标题</title>
  </head>
  <body>
    <h1>onitroad</h1>
  </body>
</html>
如何使用 CSS content 属性添加 HTML 实体

有些字符或者是为 HTML 保留的,或者是不存在于标准键盘上的。

但是 HTML 提供了实体名称或者实体编号以使用此类符号。

让我们看看如何使用 CSS content 属性添加 HTML 实体。

添加 CSS

  • 使用 :after 和 :before 伪元素。

然后,添加内容属性。

h1:before {
  content: '<';
  color: #1c87c9;
}
h1:after {
  content: '>';
  color: #1c87c9;
}
h1 {
  color: #1c87c9;
}

让我们看看完整的代码。

添加具有 content 属性的 HTML 实体的示例:

<!DOCTYPE HTML>
<html>
  <head>
    <style>
      h1:before {
        content: '<';
        color: #1c87c9;
      }
      h1:after {
        content: '>';
        color: #1c87c9;
      }
      h1 {
        color: #1c87c9;
      }
    </style>
  </head>
  <body>
    <h1>onitroad</h1>
  </body>
</html>

在下一个示例中,我们使用与前一个示例相同的符号,但使用其相应的转义 Unicode 添加它。
这里我们也使用 content 属性。

添加带有对应 Unicode 的 HTML 实体的示例:

<!DOCTYPE HTML>
<html>
  <head>
    <style>
      h1:before {
        content: '##代码##3C';
        color: #1c87c9;
      }
      h1:after {
        content: '##代码##3E';
        color: #1c87c9;
      }
      h1 {
        color: #1c87c9;
      }
    </style>
  </head>
  <body>
    <h1>onitroad</h1>
  </body>
</html>
日期:2020-06-02 22:14:55 来源:oir作者:oir