简体   繁体   English

最少混入:SVG背景和后备

[英]LESS Mixin: SVG Background & fallback

I'm trying to create a LESS mixin into which I can pass a text string to be used to construct an svg file name and a png file name. 我正在尝试创建一个LESS mixin,可以在其中传递文本字符串以构造svg文件名和png文件名。

My first attempt is below. 我的第一次尝试是在下面。 Perhaps you can see what I'm trying to do. 也许您可以看到我正在尝试做的事情。

.make-bg-svg(@name){

  @svg: ~"../images/@{name}.svg";
  @png: ~"../images/@{name}.png";
  height: 200px;
  background: transparent url(~"@{svg}");

  .no-svg & {
       background: transparent url(~"@{png}") no-repeat;
  }
}

// usage
.out-of-business {
    .make-bg-svg('out-of-business');
}

Any help would be appreciated. 任何帮助,将不胜感激。

Updated 更新

I just figured it out and updated the example above. 我只是弄清楚了并更新了上面的示例。

Just in case you don't need that many quotes, the following is equal: 以防万一您不需要那么多引号,以下内容相等:

.make-bg-svg(@name) {

  @svg: ~"../images/@{name}.svg";
  @png: ~"../images/@{name}.png";
  height: 200px;
  background: transparent url(@svg);

  .no-svg & {
       background: transparent url(@png) no-repeat;
  }
}

// usage
.out-of-business {
    .make-bg-svg(out-of-business);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM