javascript - 如何在 React JS 中使用 LESS 变量

标签 javascript css reactjs

我有以下带有硬编码颜色的标签:

<p style={{ color: '#646464' }}>

我想使用我定义的 LESS 变量,我们称它为 @tertiary-col ,我将如何使用这个变量? <p style={{ color: '@tertiary-col' }}>好像不行

最佳答案

可以使用 native 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/

关于javascript - 如何在 React JS 中使用 LESS 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51946600/

相关文章:

javascript - [ meteor 来电] : Loses prototype information

html 删除未知空格

html - 分配不重叠的 div

html - 标题中的左、中、右

javascript - React 组件未在 Bootstrap 选项卡中呈现

javascript - 从 `array` 中移除 `<select>` 中的元素

javascript - 我可以限制添加到数组中的项目数量吗?

javascript - ReactJs无法访问嵌套路由

reactjs - 如何使用 React Redux 状态有条件地显示和禁用按钮

javascript - .on ("pagecreate") 没有被调用