我可以在 <style> 中使用全局常量吗?部分? [英] can I use global constant in <style> section?

查看:33
本文介绍了我可以在 <style> 中使用全局常量吗?部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对 css 样式使用全局常量.例如,

I would like to use global constant for css style. for example,

表 td {边框:1px 纯色}

table td { border: 1px solid mycolor }

我可以在其他文件(例如配置文件)中定义 mycolor 吗?这样我就可以按颜色主题更改实际颜色.

can I define mycolor in other file such as config file? so that I can change actual color by color theme.

推荐答案

我相信您指的是全局 CSS 变量,是的,您可以但要注意浏览器支持.如果您使用的是像 SCSS 这样的预处理器,您也可以定义和共享变量.

I believe you mean global CSS variables and yes you can but be mindful of browser support. If you're using a pre-processor like SCSS, you can define and share variables too.

:root {
  --color: red;
}

和你的 Vue 组件样式块:

and your Vue component style block:

<style>
.some-class {
  color: var(--color);
}
</style>

SCSS 示例

$color: red;

和你的 Vue 组件样式块:

and your Vue component style block:

<style lang="scss">
@import "~/assets/vars.scss";

.some-class {
  color: $color;
}
</style>

这篇关于我可以在 &lt;style&gt; 中使用全局常量吗?部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆