::target-text
Baseline 2024
Newly available
Since December 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
::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