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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:45:31  来源:igfitidea点击:

Background images path in Sass and Compass

cssrubycompass-sasssass

提问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 backgroundand 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 ?1327592426from each background image?

以及如何摆脱?1327592426从每个背景图像生成的这个自动?

回答by maxbeatty

You should use the image-urlURL 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-busterto false to remove the generated ?1327592426

您应该使用image-urlURL 助手。它“生成相对于项目图像目录找到的资产的路径”,您在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')