LESS 缺省变量
LESS 缺省变量
默认变量只有在尚未设置时才能设置变量。此功能不是必须的,因为可以通过后定义变量轻松地覆盖变量。
例子
<html> <head> <link rel = "stylesheet" href = "style.css" type = "text/css" /> <title>LESS Default Variables</title> </head> <body> <h1>Welcome to Tutorialspoint</h1> <p>LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p> </body> </html>
创建style.less 文件.
/*style.less*/ @import "http://www.kaifaxueyuan.com/less/lib.less"; // first declaration of @color @color: green; // this will override @color defined previously p { color : @color; }
上面的代码会从路径https://www.kaifaxueyuan.com/less/lib.less导入lib.less文件到style.less
/*lib.less*/ @color: blue;
使用下面的命令编译less文件
lessc style.less style.css
得到css文件
/*style.css*/ p { color: green; } 输出
执行以下步骤:
保存上述的HTML代码到 less_default_variables.html 文件。
在浏览器中打开该HTML文件,得到如下输出显示。