- 语言特性
- LESS - 嵌套规则
- LESS - 嵌套指令和冒泡
- LESS - 运算
- LESS - 转义
- LESS - 函数
- LESS - 命名空间和访问器
- LESS - 作用域
- LESS - 注释
- LESS - 导入
- LESS - 变量
- LESS - 扩展
- LESS - Mixin
- LESS - 参数化 Mixin
- LESS - Mixin 作为函数
- LESS - 向 Mixin 传递规则集
- LESS - 导入指令
- LESS - 导入选项
- LESS - Mixin 保护
- LESS - CSS 保护
- LESS - 循环
- LESS - 合并
- LESS - 父选择器
- 函数
- LESS - 其他函数
- LESS - 字符串函数
- LESS - 列表函数
- LESS - 数学函数
- LESS - 类型函数
- LESS - 颜色定义函数
- LESS - 颜色通道函数
- LESS - 颜色运算
- LESS - 颜色混合函数
- 使用
- LESS - 命令行使用
- 在浏览器中使用 LESS
- LESS - 浏览器支持
- LESS - 插件
- LESS - 编程使用
- LESS - 在线编译器
- LESS - GUI
- LESS - 编辑器和插件
- LESS - 第三方编译器
- LESS - 框架
- LESS 有用资源
- LESS - 快速指南
- LESS - 有用资源
- LESS - 讨论
LESS - URL
描述
变量可以用来保存 URL。
示例
以下示例演示了在 LESS 文件中使用变量保存URL:
<html>
<head>
<link rel = "stylesheet" href = "style.css" type = "text/css" />
<title>LESS URLs</title>
</head>
<body>
<div class = "myclass">
</div>
</body>
</html>
现在创建style.less文件。
style.less
@images: "https://tutorialspoint.com";
.myclass {
background : url("@{images}/less/images/less_variables/birds.jpg");
width:800px;
height:500px;
}
您可以使用以下命令将style.less编译为style.css:
lessc style.less style.css
执行以上命令;它将自动创建包含以下代码的style.css文件:
style.css
.myclass {
background: url("https://tutorialspoint.com/less/images/less_variables/birds.jpg");
width: 800px;
height: 500px;
}
输出
请按照以下步骤查看以上代码的工作原理:
将以上HTML代码保存在less_variables_interpolation_url.html文件中。
在浏览器中打开此HTML文件,将显示以下输出。
less_variables.htm
广告