有没有办法为LESS文件设置公共图像路径? [英] Is there a way to set a common image path for LESS files?
本文介绍了有没有办法为LESS文件设置公共图像路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 LESS 样式语言。
请考虑以下CSS:
.side-bg
{
background:url(../img/layout/side-bg.jpg) top no-repeat;
}
现在我的所有图像都在文件夹 .. / img /
我想要能够设置一个变量作为图像路径,并使用它像这样:
Right now all of my images are in the folder ../img/
I wanted to be able to set a variable as the image path and use it like so:
@image-path: ../img;
.side-bg
{
background:url(@image-path/layout/side-bg.jpg) top no-repeat;
}
这不是一个巨大的交易,我可以总是使用查找和替换如果图像文件夹已经改变。我刚刚开始学习LESS,并且想知道这样的东西是否可能。
This does not work however. Its not a huge deal, I could always use find and replace if the image folder ever changed. I am just starting to learn LESS and was wondering if something like this is possible.
推荐答案
尝试使用字符串插值。在文档中查找变量插值。
Try using string interpolation for things like this. Look for "variable interpolation" in docs.
@base-url: "http://assets.fnord.com";
background-image: url("@{base-url}/images/bg.png");
这篇关于有没有办法为LESS文件设置公共图像路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文