HTML - <del> 标签



HTML <del> 标签用于标记网站上已删除的文本内容。它代表“已删除文本”,表示已从文档中删除的一段文本。这在呈现“修订跟踪”或源代码提供不同信息时非常有用。当我们使用 <del> 标签时,浏览器通常会在已删除的文本上添加删除线。

注意: 要查找文档中已删除和插入的内容,请将 <ins> 标签与 <del> 标签一起使用,这将显示已删除和插入的文本。

语法

<del >...</del >

属性

HTML del 标签支持 HTML 的全局事件属性。也接受一些特定的属性,如下所示。

属性 描述
cite URL 它定义了引文来源的 URL。
datetime YYYY-MM-DDThh:mm:ssTZD 保存文本被删除的日期和时间。

HTML del 标签示例

在这些示例中,我们将看到 del 标签在文本元素上的用法。我们还将使用内部 CSS 装饰我们的 del 标签。

使用 del 标签在文本上添加删除线

在以下示例中,我们创建一个 HTML 文档,并使用 <del> 标签在不需要的内容上添加删除线。

<!DOCTYPE html>
<html>
<body>
   <h2>Example of del tag </h2>
   <p>
      This is tutorialpoint; here learning is easy 
      <del>and difficult</del>, 
      so their caption is easy to learn. 
   </p>
   <p>
      <del>I am deleted paragraph</del>
   </p>
</body>
</html>

使用带属性的 del 标签

在这个示例中,我们将使用 cite 和 datetime 属性来提及上下文的来源和删除日期。

<!DOCTYPE html>
<html>
<body>
   <h2>Example of del tag </h2>
   <p>
      This is tutorialpoint; here learning is easy 
      <del cite=
"https://tutorialspoint.com/index.htm">
      and difficult</del>, 
      so their caption is easy to learn. 
   </p>
   <p>
      <del datetime="2024-01-03T12:00:00Z">I am deleted paragraph</del>
   </p>
</body>
</html>

使用 CSS 样式化已删除元素

考虑以下示例,我们使用 <del> 标签为不需要的内容添加删除线,并使用 CSS 属性设置已删除内容的背景颜色。

<!DOCTYPE html>
<html>
<head>
   <style>
      del {
         text-decoration: line-through;
         background-color: #fbb;
         color: #555;
      }

      ins {
         text-decoration: none;
         background-color: #d4fcbc;
      }
   </style>
</head>
<body>
   <p>There is <del>nothing</del>
      <ins>no code</ins> either good or bad, but <del>thinking</del>
      <ins>running it</ins> makes it so.
   </p>
   <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, <del>when an unknown printer took a galley of type and scrambled it to make a type specimen book</del>. </p>
</body>
</html>

支持的浏览器

标签 Chrome Edge Firefox Safari Opera
del
html_tags_reference.htm
广告
© . All rights reserved.