Search code examples
csssasscompass-sass

Sass/Compass - Use variables for relative paths


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


Solution

  • I think you need to interpolate the variable:

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