在Sass中有一个变量在图像路径? [英] Have a variable in images path in Sass?

查看:130
本文介绍了在Sass中有一个变量在图像路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个变量,其中包含我的CSS文件中所有图像的根路径。我不能完全明白这是否可能在纯Sass(实际的web项目不是RoR,所以不能使用asset_pipeline或任何那个花哨的爵士乐)。

I want to have one variable that contains the root path to all my images in my CSS file. I can't quite figure out if this is possible in pure Sass (the actual web project is not RoR, so can't use asset_pipeline or any of that fancy jazz).

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

Here's my example that doesn't work. On compile it balks at first instance of variable in the background url property saying ("Invalid CSS after "..site/background": expected ")").

定义函数以返回路径:

//Vars
$assetPath : "/assets/images";

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

使用函数:

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

任何帮助将不胜感激。 >

Any help would be appreciated.

推荐答案

您是否尝试过 Interpolation 语法?

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

这篇关于在Sass中有一个变量在图像路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆