<s>:刪除線元素
試一試
屬性
此元素僅包含 全域性屬性。
無障礙訪問
大多數螢幕閱讀器技術在其預設配置中不會宣佈 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 |
瀏覽器相容性
BCD 表格僅在瀏覽器中載入
另請參閱
<strike>元素(<s>元素的另一個化身)已過時,不應再在網站上使用。- 如果資料已被刪除,則應使用
<del>元素。 - 應使用 CSS
text-decoration-line屬性來實現<s>元素以前的可視外觀。