指南针:生成精灵,加上精灵中每个图像的宽度/高度
我正在使用 Compass(一个 CSS 框架)来生成精灵图像。 它可以工作,但指南针仅为每个图像生成一个背景位置。
是否还可以获取精灵中每个图像的宽度和高度?
这是我的代码:
@import "ico/*.png";
@include all-ico-sprites;
生成的代码:
.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;
}
以及我想要的代码:
.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;
}
谁能向我解释一下我该怎么做? 谢谢。
I'm using Compass (a CSS Framework) to generate sprite images.
It work, but compass generate only a background-position for each image.
Is it possible to get also the width and the height for each image in the sprite?
This is my code:
@import "ico/*.png";
@include all-ico-sprites;
The generated code:
.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;
}
And the code i would like to have:
.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;
}
Can anyone explain to me how I can do that?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可行:
但您可能需要考虑使用配置变量的记录方式:
http://compass-style.org/help/tutorials/spriting/
您只需在之前指定配置变量即可进口。在您的情况下:
将
true
发送到 all include 有效,但由于它没有记录,因此配置变量似乎是首选方法。除了尺寸之外,还有其他可用的配置变量:
This works:
But you may want to consider the documented way of using configuration variables:
http://compass-style.org/help/tutorials/spriting/
You just specify the config variable before the import. In your case:
Sending
true
to the all include works, but as it's undocumented, it would seem that configuration variables are the preferred method.Aside from dimensions these are the other configuration variables available:
我找到了解决方案。
只需将 true 作为第二个参数传递即可:
非常简单。
I found the solution.
Just pass true as the second argument :
Quite simply.