Background Images Path in SASS and Compass

Background images path in Sass and Compass

You should use the image-url URL helper. It "generates a path to an asset found relative to the project's images directory" which you defined in your config.rb. You can also set the third parameter $cache-buster to false to remove the generated ?1327592426

Sass:

// image-url arguments:
// $path: path relative to images directory in config.rb
// $path-only: if true, will cause only the path to be returned instead of a `url()` function
// $cache-buster: When set to `false` no cache buster will be used (i.e. `?313420982`)
$header-img: image-url('background/sass.gif', false, false)
background-image: $header-img

Generated CSS:

background-image: url('images/background/sass.gif')

Have a variable in images path in Sass?

Have you tried the Interpolation syntax?

background: url(#{$get-path-to-assets}/site/background.jpg) repeat-x fixed 0 0;

Sass/Compass - Use variables for relative paths

I think you need to interpolate the variable:

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


Related Topics



Leave a reply



Submit