简体   繁体   English

CSS变量与CSS模块@value

[英]CSS Variables vs CSS Modules @value

I was wondering what exactly is the difference between the css function var(--red) and @value red from css modules. 我想知道css函数var(-red)和css模块中的@value red之间到底有什么区别。

CSS Modules Example: CSS模块示例:

@value red from "./color.m.css";

.background {
    background-color: red;
}

CSS Var() Example: CSS Var()示例:

@import "./color.m.css";

.background {
    background-color: var(--red);
}

Is there an advantage using one of them? 使用其中之一是否有优势?
Thanks in advance for helping me out! 在此先感谢您对我的帮助!

CSS modules @value is CSS模块@value是

  1. Similar to preprocessor(sass/less) variable. 类似于预处理器(sass / less)变量。 Its alive in compile time. 它在编译时还活着。
  2. As it compiles to plain css. 由于它可以编译为普通的CSS。 It works in every browser. 它适用于所有浏览器。

CSS Var() is CSS Var()是

  1. A live variable in css file. css文件中的活动变量。 Any change to its value is reflected live in the elements its being used. 价值的任何变化都会实时反映在其使用的元素中。
  2. As its a new css feature, Works in modern browsers only 作为一项新的CSS功能,仅适用于现代浏览器

As of i know modules are very useful as they can import any where they want and can be used.but variables can only be used inside page with global and inline scope. 就我所知,模块非常有用,因为它们可以导入所需的任何位置并可以使用。但是变量只能在具有全局范围和内联范围的页面内使用。

module and css variable are incomparable as i think so. 模块和css变量是我无法比拟的。

please check this link for more reference. 请检查此链接以获取更多参考。

Click here for Css module description 单击此处获取CSS模块说明

Css varible description CSS变量描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM