【发布时间】:2022-01-16 01:07:15
【问题描述】:
我正在使用 react 并想更改文本突出显示颜色。 首先,我找到了一个可行的解决方案:
高亮.css
::selection {
background:#fbc308;
color: black
}
somecomponent.tsx
import './highlight.css'
但是,它会更改每个元素的文本突出显示颜色,这不是我想要的。 而且,
<div style={{"::selection" : {
background:"#fbc308",
color: "black"}}}><p>Something</p></div>
没用(错误)
所以,我选择了:
.somecomponent p::selection {
...style
}
但是它只改变 p 元素。我想更改组件中的所有文本突出显示颜色。
谢谢。
【问题讨论】:
-
您是否尝试将
.somecomponent p::selection替换为.somecomponent *::selection?
标签: css reactjs typescript jsx highlight