html - Select Pseudo-element (such ::before and ::after ) of element in DOM
问题描述
Here is my code:
HTML:
<div class="class"></div>
CSS:
.class:before {
content: "text";
color: red;
}
I need to change the red colour to green in DOM (no jQuery)
解决方案
是的,使用 css 变量
const Root = document.documentElement;
Root.style.setProperty('--mycolor', 'green');
:root {
--mycolor : red;
}
.class:before {
content: "text";
color: var(--mycolor);
}
<div class="class"></div>
推荐阅读
- python - Python/Pandas:数据框合并和填充
- python - CentOS7 的 Docker 映像中的 PIP python setup.py egg_info
- python - ValueError:传递值的形状为 (6, 6),在 pandas 中合并两个 df 时,索引暗示 (4, 6) 错误
- javascript - 如何根据过滤器显示来自 API 的数据?
- javascript - SVG 元素上的 setAttribute 后的 JS 错误不可捕获
- amazon-web-services - 带有 ECS 的 AWS 负载均衡器。如何解决运行状况检查失败的问题?
- windows - 通过 PowerShell 重新连接蓝牙设备
- c# - DataTable 末尾有一个下拉列
- go - have(string) want() 看不懂
- sql - sql查询中自动添加月份的日期参数声明