コンパスのスプライト ジェネレーターを使用すると、ジェネレーターはピクセルに基づいて CSS ルールを作成します。
コード例:
@import 'compass/utilities/sprites';
$sprite-2-layout: horizontal;
@import "sections/anatomy-sprite-test/sprite-2/*.png";
@include all-sprite-2-sprites;
$sprite-3-layout: horizontal;
@import "sections/anatomy-sprite-test/sprite-3/*.png";
@include all-sprite-3-sprites;
$sprite-4-layout: horizontal;
@import "sections/anatomy-sprite-test/sprite-4/*.png";
@include all-sprite-4-sprites;
出力例:
/* line 84, ../../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.1/stylesheets/compass/utilities/sprites/_base.scss */
.sprite-2-00 {
background-position: 0 0;
}
/* line 84, ../../../../../../../../../../../Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.1/stylesheets/compass/utilities/sprites/_base.scss */
.sprite-2-00 {
background-position: -244px 0;
}
それらを応答的に使用するために、これらをパーセンテージで生成できる方法はありますか?
独自に作成しましたが、特定のブラウザではうまく動作しません。これが私のアプローチです:
@mixin sprite-percentage-step-generate($steps, $single_image_width) {
$total_image_width: ($single_image_width * $steps) - $single_image_width;
background-position: 0 0;
img {
display: none;
}
@for $i from 0 through ($steps - 1) {
$step_width: $i * $single_image_width;
&.step-#{$i} {
background-position: percentage(($step_width / $total_image_width)) 0;
// We include these to see the relation between the percentage and the step count
img {
display: none;
}
}
}
}
ピクセルベースのアプローチが最適に機能するように、ジェネレーターが特別な種類の最適化を行う可能性があるため、これは良い考えではないでしょうか?
繰り返しますが、質問は次のとおりです。スプライトの位置がピクセルではなくパーセンテージで生成される CSS を Compass で生成する方法はありますか?