指南针:生成精灵,加上精灵中每个图像的宽度/高度

Eti*_*nne 32 css sass css-sprites compass-sass

我正在使用Compass(一个CSS框架)来生成精灵图像.它工作,但指南针只为每个图像生成一个背景位置.

是否有可能获得精灵中每个图像的宽度和高度?

这是我的代码:

@import "ico/*.png";
@include all-ico-sprites;
Run Code Online (Sandbox Code Playgroud)

生成的代码:

.ico-sprite, .ico-bag-blue, .ico-bag-black {
  background: url('../images/ico-s78b1a1919b.png') no-repeat;
}

.ico-bag-blue {
  background-position: 0 0;
}

.ico-bag-black {
  background-position: 0 -24px;
}
Run Code Online (Sandbox Code Playgroud)

我想要的代码:

.ico-sprite, .ico-bag-blue, .ico-bag-black {
  background: url('../images/ico-s78b1a1919b.png') no-repeat;
}

.ico-bag-blue {
  background-position: 0 0;
  width:40px;
  height:24px;
}

.ico-bag-black {
  background-position: 0 -24px;
  width:44px;
  height:30px;
}
Run Code Online (Sandbox Code Playgroud)

谁能向我解释我怎么能这样做?谢谢.

num*_*407 74

这有效:

@include all-<map>-sprites(true);
Run Code Online (Sandbox Code Playgroud)

但您可能需要考虑使用配置变量的文档化方法:http:
//compass-style.org/help/tutorials/spriting/

您只需在导入之前指定config变量.在你的情况下:

$ico-sprite-dimensions: true;
@import "ico/*png".
@include all-ico-sprites;
Run Code Online (Sandbox Code Playgroud)

发送true到all包括作品,但由于它没有文档,似乎配置变量是首选方法.

除尺寸外,这些是可用的其他配置变量:

$<map>-spacing           // space in px around the sprites
$<map>-repeat            // whether to repeat the sprite bg
$<map>-position          // the x position of the sprite on the map
$<map>-sprite-base-class // the base class (default ".<map>-sprite")
$<map>-clean-up          // whether to delete old image maps
$<map>-<sprite>-spacing  // spacing, for individual sprites
$<map>-<sprite>-repeat   // repeat, for individual sprites
$<map>-<sprite>-position // position, for individual sprites
Run Code Online (Sandbox Code Playgroud)


Eti*_*nne 7

我找到了解决方案.只传递true作为第二个参数:

@include all-ico-sprites(true);
Run Code Online (Sandbox Code Playgroud)

很简单.