sass background mixins using url [duplicate]

那年仲夏 提交于 2019-12-10 13:28:51

问题


guys i would like to create a background mixin instead writing repeated url

 @mixin bgimage($name){
  $url:"../images/$name.png";
 background: url($url);}

and,it never accept the valuee to $name variable

i called it by

     @include bgimage(name.png);

and in css the output is came wrong like this

     background: url("../images/$name.png");

is there any way to write the url in mixin ? ot how to do it in short way


回答1:


try with variable interpolation of #{$name}

@mixin bgimage($name) {
  $url:"../images/#{$name}.png";
  background: url($url);
}

and pass the filename, without extension, as a mixin parameter:

@include bgimage(your-png-file-without-extension);

since it is already appended in the $url variable of your mixin



来源:https://stackoverflow.com/questions/17854975/sass-background-mixins-using-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!