Sass/Compass - Use variables for relative paths

落花浮王杯 提交于 2019-12-01 11:43:37

问题


Is it possible to use variables to set relative paths in Sass? I've tried to do it but just keep getting errors. In my admin css files I'm trying to avoid writing background(../../img/admin/img.jpg) for any images that need accessing from the css. I've tried writing something like

$admin_img: '../../img/admin';
body {
    background: url($admin_img/background.png);
}

This code won't work and keeps saying that it expects ')' but found '.png);'

Is it possible to set the paths using variables and how can it be done? Thanks


回答1:


I think you need to interpolate the variable:

$admin_img: '../../img/admin'; 
body { 
    background: url(#{$admin_img}/background.png); 
}


来源:https://stackoverflow.com/questions/11743260/sass-compass-use-variables-for-relative-paths

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