javascript - 如何在 React JS 中使用 LESS 变量
问题描述
我有以下带有硬编码颜色的标签:
<p style={{ color: '#646464' }}>
我想使用我定义的 LESS 变量,我们称之为它@tertiary-col
,我将如何使用这个变量?<p style={{ color: '@tertiary-col' }}>
似乎不起作用
解决方案
可以使用本机var()
来执行此操作。
通过将变量放入:root
然后它可以在您需要使用它的任何地方使用。
你会这样做--tertiary-col: @tertiary-col;
,但为了片段的目的,我已经输入了一个实际的十六进制值。
:root {
--tertiary-col: @tertiary-col; /* this is what you would do */
--tertiary-col: #646464; /* @tertiary-col; */
}
<p style="color: var(--tertiary-col)">Some text</p>
这是一个关于 css 变量的优秀教程:https ://codepen.io/abcretrograde/full/xaKVNx/
推荐阅读
- linux - rsync 目录变成更扁平的结构
- ssl - hunchentoot 用 ssl 定义简单处理程序?
- angular - 如何使用 Angular 5 对 HTTP GET 响应进行排序以一次获取一个元素
- filter - Odoo 11 - 按公司过滤产品
- routes - 如何设置在查询字符串中采用多个参数的 Phoenix 路由
- python - 为什么我的 Python 程序在运行第一个循环后关闭?
- python - 如何将参数从 mock.patch 传递给 new_callable?
- primefaces - 如何使用 selectOneRadio 切换所需元素
- java - 从串行通信端口(COM1)读取数据时无法退出循环
- php - 上传时无法在php中减小图像文件大小