<s>: Strikethrough 元素
<s> HTML 元素用于渲染带有删除线(划掉)的文本。使用 <s> 元素表示不再相关或不再准确的内容。然而,当指示文档编辑时,<s> 不适用;此时,应酌情使用 <del> 和 <ins> 元素。
试一试
<p><s>There will be a few tickets available at the box office tonight.</s></p>
<p>SOLD OUT!</p>
s {
/* Add your styles here */
}
属性
此元素仅包含全局属性。
无障碍
在大多数屏幕阅读器的默认配置中,s 元素的出现不会被播报。可以通过使用 CSS 的 content 属性,以及 ::before 和 ::after 伪元素来使其被播报。
css
s::before,
s::after {
clip-path: inset(100%);
clip: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
s::before {
content: " [start of stricken text] ";
}
s::after {
content: " [end of stricken text] ";
}
一些使用屏幕阅读器的用户会故意禁用播报会产生额外冗余的内容。因此,重要的是不要滥用此技术,只将其应用于不了解内容被划掉会严重影响理解的情况。
示例
css
.sold-out {
text-decoration: line-through;
}
html
<s>Today's Special: Salmon</s> SOLD OUT<br />
<span class="sold-out">Today's Special: Salmon</span> SOLD OUT
结果
技术摘要
规范
| 规范 |
|---|
| HTML # the-s-element |
浏览器兼容性
加载中…
另见
<s>元素的“另一个自我”——<strike>元素——已废弃,不应再用于网站。- 如果数据已被删除,则应使用
<del>元素。 - 应使用 CSS 的
text-decoration-line属性来实现<s>元素之前的视觉外观。