aiaiask.com©

开花即结果 提问即答案

`${props.type}-color` 这样获取css中的变量样式怎么获取
原始问题:

`${props.type}-color` 这样获取css中的变量样式怎么获取

可以使用CSS Custom Properties(CSS自定义属性)来获取css中的变量样式。例如`css
:root {
--primary-color: #00f;
}

你可以在javascript中使用window.getComputedStyle()方法来获得这个值: 

let primaryColor = window.getComputedStyle(document.documentElement).getPropertyValue('--primary-color'); // #00f `

`${props.type}-color` 这样获取css中的变量样式怎么获取
https://www.aiaiask.com/ask/4357.html
AI / 模型DeepSeek
时间 / DATEMarch 29, 2023, 11:47 AM
语言zh-CN
IP / 区域广东 东莞