::target-text

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

::target-text CSS 伪元素代表了浏览器在支持文本片段技术时所滚动到的文字。它使得作者可以选择高亮一段文字的方式。

css
::target-text {
  background-color: pink;
}

语法

css
::target-text {
  /* ... */
}

示例

高亮文本片段

css
::target-text {
  background-color: rebeccapurple;
  color: white;
}

要实际查看 CSS 效果,请参考 scroll-to-text 演示

规范

Specification
CSS Pseudo-Elements Module Level 4
# selectordef-target-text

浏览器兼容性

BCD tables only load in the browser

参见