コンパスで生成されたアイコン スプライトを 2 つの異なるシナリオで使用したいと考えています。
- アイコンは元のサイズで使用してください。
- CSS3 プロパティを使用した小さいバージョンと同じアイコンを使用します
background-size
。
私は最初にこれを行います:
$logo-spacing: 20px;
@import "logo/*.png";
@include all-logo-sprites;
これで、作成された一般的な CSS クラス.logo-twitter
などを使用できるようになりました。
2 つは、これを使用できる 2 番目の結果を達成します ( darren131 / gist:3410875 - Compass でスプライトのサイズを変更します):
@mixin resize-sprite($map, $sprite, $percent) {
$spritePath: sprite-path($map);
$spriteWidth: image-width($spritePath);
$spriteHeight: image-height($spritePath);
$width: image-width(sprite-file($map, $sprite));
$height: image-height(sprite-file($map, $sprite));
@include background-size(ceil($spriteWidth * ($percent/100)) ceil($spriteHeight * ($percent/100)));
width: ceil($width*($percent/100));
height: ceil($height*($percent/100));
background-position: 0 floor(nth(sprite-position($map, $sprite), 2) * ($percent/100) );
}
.my-other-div-with-small-logos {
.logo-twitter {
$spriteName: twitter;
$percentage: 40;
@include resize-sprite($logo-sprites, $spriteName, $percentage);
}
}
しかし、約 30 個のロゴがある場合は、スプライト クラスごとにこれを手動で繰り返す必要があります。
フォルダを 2 回、元のサイズで 1 回、backround-size
プロパティで 2 回インポートすることはできますか? <div class="my-other-div-with-small-logos">
または、前述のメソッドを変更して、アイコンが小さく表示される別のクラス内にすべてのクラスを自動的に作成しますか?
それとも、ここで間違った方向に考えていますか?