在Sass中的图像path有一个variables?

我想有一个variables,它包含我的CSS文件中所有图像的根path。 我不能完全弄清楚,如果这可能在纯Sass(实际的Web项目不是RoR,所以不能使用asset_pipeline或任何那个华丽的爵士)。

这是我的例子,不起作用。 在编译它在后台url属性variables的第一个实例balks说( "Invalid CSS after "..site/background": expected ")" )。

定义函数返回path:

 //Vars $assetPath : "/assets/images"; //Functions @function get-path-to-assets($assetPath){ @return $assetPath; } 

使用function:

 body { margin: 0 auto; background: url($get-path-to-assets/site/background.jpg) repeat-x fixed 0 0; width: 100%; } 

任何帮助,将不胜感激。

你是否尝试过插值语法?

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

不需要function:

 $assetPath : "/assets/images"; ... body { margin: 0 auto; background: url(#{$assetPath}/site/background.jpg) repeat-x fixed 0 0; width: 100%; } 

有关详细信息,请参阅插值文档 。

正在寻找同一个问题的答案,但认为我find了一个更好的解决scheme: http : //blog.grayghostvisuals.com/compass/image-url/

基本上,您可以在config.rb中设置图像path,并使用image-url()助手