Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 我可以使用Less根据类名设置CSS背景图像吗?_Html_Css_Less - Fatal编程技术网

Html 我可以使用Less根据类名设置CSS背景图像吗?

Html 我可以使用Less根据类名设置CSS背景图像吗?,html,css,less,Html,Css,Less,我有一个生成DOM的模板技术,而不是生成CSS。在我的模板中,我正在迭代一个对象列表,其中包含图标图像的名称 我想做的是将图标图像名称作为CSS类使用。然后使用less,将背景图像路径设置为基于该类名的内容: .className {background: url(../some/path/constant/[@className].png);} …保存时需要在模板本身中设置背景样式。是!!设置CSS背景并不依赖于更少的内容。如果你能用CSS来做,那么你总是可以用更少的方法来做 设置不同的背景

我有一个生成DOM的模板技术,而不是生成CSS。在我的模板中,我正在迭代一个对象列表,其中包含图标图像的名称

我想做的是将图标图像名称作为CSS类使用。然后使用less,将背景图像路径设置为基于该类名的内容:

.className {background: url(../some/path/constant/[@className].png);}

…保存时需要在模板本身中设置背景样式。

是!!设置CSS背景并不依赖于更少的内容。如果你能用CSS来做,那么你总是可以用更少的方法来做

设置不同的背景图像(较少方式)

在HTML中:

<div class="className1>
      <span> This will have image1.png as background</span>
</div>
<div class="className2>
      <span> This will have image2.png as background</span>
</div>
<div class="className3>
      <span> This will have image3.png as background</span>
</div>

这将以image2.png为背景

然后我的HTML是好的和干净的无论什么。。。
<div class="className1>
      <span> This will have image1.png as background</span>
</div>
<div class="className2>
      <span> This will have image2.png as background</span>
</div>
<div class="className3>
      <span> This will have image3.png as background</span>
</div>