css - Sass 和 Compass 中的背景图片路径

标签 css ruby compass-sass sass

这个在config.rb文件中有提到

images_dir = "images"

我在 images 文件夹中的元素中使用 2 个文件夹存放图像

images
images/background/
images/content/

如果 images/background/ 文件夹中有任何图像,那么我应该如何在 css background 和 Sass 变量中添加图像路径?

$header-img: "sass.gif"; 

background-image: url('sass.gif?1327592426');

以及如何从每个背景图像中删除这个自动生成的 ?1327592426

最佳答案

您应该使用image-url URL helper .它“生成相对于元素图像目录找到的 Assets 的路径”,您在 config.rb 中定义了该路径。也可以设置第三个参数$cache-buster为false来移除生成的?1327592426

萨斯:

// 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

生成的 CSS:

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

关于css - Sass 和 Compass 中的背景图片路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9021306/

相关文章:

css - 将 CSS 应用于 Crystal 报表

css - 如何在 JQGrid TreeGrid 中隐藏行之间的行

css - 为什么在使用显示 :flex; & flex-flow:colum; and use oreder:1/2; on child-elements? 时图像不显示在 safari 上

css - 使用SASS为linear-gradient动态添加色标

ruby-on-rails - Errno::ECONNREFUSED 无法建立连接,因为

css - 无法更改 Drupal 中已修改主题的 CSS

ruby-on-rails - 如何自定义 rails activerecord 验证错误消息以显示属性值

Ruby 从文件中读取变量

ruby - capybara select2 助手

css - 如何在 SASS mixin 中使用 !default?