CSS Sass 和 Compass 中的背景图像路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9021306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Background images path in Sass and Compass
提问by Jitendra Vyas
This is mentioned in config.rb file
这在 config.rb 文件中提到
images_dir = "images"
I use 2 folder for images in my projects inside images folder
我在图像文件夹内的项目中使用 2 个文件夹作为图像
images
images/background/
images/content/
If any images is inside images/background/
folder then how i should add the path for image in css background
and Sass variables?
如果images/background/
文件夹内有任何图像,那么我应该如何在 cssbackground
和 Sass 变量中添加图像的路径?
$header-img: "sass.gif";
and
和
background-image: url('sass.gif?1327592426');
And how to get rid of this auto generated ?1327592426
from each background image?
以及如何摆脱?1327592426
从每个背景图像生成的这个自动?
回答by maxbeatty
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
您应该使用image-url
URL 助手。它“生成相对于项目图像目录找到的资产的路径”,您在config.rb
. 您还可以将第三个参数设置$cache-buster
为 false 以删除生成的?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:
生成的 CSS:
background-image: url('images/background/sass.gif')