如何在 CSS 中使用变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7247202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 01:27:44  来源:igfitidea点击:

How to use variable in CSS?

cssvariablesglobal-variables

提问by Safran Ali

Possible Duplicate:
Create a variable in .CSS file for use within that .CSS file

可能的重复:
在 .CSS 文件中创建一个变量以在该 .CSS 文件中使用

I heard about that we can declare/define variable in CSS and use them like global variables like this:

我听说我们可以在 CSS 中声明/定义变量,并像这样使用全局变量:

@nice-blue: #5B83AD;

#header { color: @nice-blue; }

So anyone knows how to use them?

那么有人知道如何使用它们吗?

回答by balexandre

For that you need to use Lessor Sasswhich are CSS Dynamic languages.

为此,您需要使用CSS 动态语言LessSass

here's some comparisonbetween both technologies.

这是两种技术之间的一些比较

回答by Jason Gennaro

You need to use something like SASS

你需要使用类似 SASS 的东西

http://sass-lang.com/#variables

http://sass-lang.com/#variables

or Less

或更少

http://lesscss.org/

http://lesscss.org/

回答by S.M.

There is a language written on top of CSS which make use of variables like you asked, it's called LessCSS

有一种写在 CSS 之上的语言,它使用你问的变量,它叫做LessCSS