LoginSignup
11
11

More than 5 years have passed since last update.

CompassでCSSスプライト(Retina対応)

Last updated at Posted at 2013-05-16

Compassプロジェクトにimages/spritesフォルダを作成
素材画像をPNG形式で、表示サイズの2倍で作成しておく

@import "compass/css3/background-size";

$map: sprite-map("sprites/*.png", $layout: smart);
$map-img: sprite-url($map);

@mixin sprite-background($name, $text: false) {
    display: inline-block; // block;

    width: image-width(sprite-file($map, $name)) / 2;
    height: image-height(sprite-file($map, $name)) / 2;
    background-image: $map-img;
    background-repeat: no-repeat;
    $pos: sprite-position($map, $name);
    background-position: (nth($pos, 1) / 2) (nth($pos, 2) / 2);
    @include background-size(ceil(image-width(sprite-path($map)) / 2) auto);

    @if not $text {
        vertical-align: top;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
        font: 0/0 a;
        text-shadow: none;
        color: transparent;
    }
}

使い方


.hoge {
    @include sprite-background("hoge"); // images/sprites/hoge.png
}
11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11