开发者

Multiple Background Images using Sass / Compass

开发者 https://www.devze.com 2023-03-02 14:48 出处:网络
The following generates a base64 inline-image using sass/compass: background-image:inline-image(\"paper.jpg\", \'image/jpg\');

The following generates a base64 inline-image using sass/compass:

background-image:inline-image("paper.jpg", 'image/jpg');

Is there a way to do multiple bac开发者_Go百科kground images, or do I have to precompress them myself to do it?

Thanks.


The inline-image function just outputs the url() string, so you can use multiple by doing this:

background: inline-image("front-image.jpg", 'image/jpg') no-repeat, inline-image("back-image.jpg", 'image/jpg') repeat-x

And you'll get the following css:

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

I added "no-repeat" and "repeat-x" otherwise the front-image will repeat and cover the back-image.


I'm use sencha touch 2 and found next sass extension for this:

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

See usages:

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消