Sass / Compass使用多个背景图片

11
下面这段代码使用sass/compass生成一个base64内联图像:
background-image:inline-image("paper.jpg", 'image/jpg');

有没有一种方法可以使用多个背景图像,或者我必须自己预压缩它们才能这样做?

谢谢。

2个回答

8
内联图像函数只输出url()字符串,因此您可以通过以下方式使用多个:
background: inline-image("front-image.jpg", 'image/jpg') no-repeat, inline-image("back-image.jpg", 'image/jpg') repeat-x

您将获得以下CSS:

background: url('data:"image/jpg";base64,FRONTIMAGEDATAHERE') no-repeat, url('data:"image/jpg";base64,BACKIMAGEDATAHERE') repeat-x;

我添加了"no-repeat"和"repeat-x"属性,否则前景图片会重复并覆盖背景图片。


请注意,如果您希望在使用“background”简写时应用背景颜色,则仅允许在最后一层中使用:“请注意,在<final-bg-layer>中可以使用颜色,但在<bg-layer>中不允许使用”。 - steveax

0

我正在使用Sencha Touch 2,并找到了适用于它的下一个Sass扩展:

theme_images.rb:

module SenchaTouch
  module SassExtensions
    module Functions
      module ThemeImages
        def theme_image(theme, path, mime_type = nil)
          path = path.value
          images_path = File.join(File.dirname(__FILE__), "..", "images", theme.value)
          real_path = File.join(images_path, path)
          inline_image_string(data(real_path), compute_mime_type(path, mime_type))
        end
      end
    end
  end
end

module Sass::Script::Functions
  include SenchaTouch::SassExtensions::Functions::ThemeImages
end

compass_init.rb:

# This file registers the sencha-touch framework with compass
# It's a magic name that compass knows how to find.
dir = File.dirname(__FILE__)
require File.join(dir, 'lib', 'theme_images.rb')

Compass::Frameworks.register 'sencha-touch', dir

查看用法:

background: theme_image($theme-name, "clear_icon.png") no-repeat;
-webkit-mask: theme_image($theme-name, "select_mask.png");
-webkit-mask-image: theme_image($theme-name, "pictos/arrow_down.png");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接