2012-03-16 164 views
5

我正在使用inline-image函数来创建图标类。这是我目前SCSS:SCSS - 获取图像尺寸

.folder { 
    background: inline-image("icons/home/folder.png", 'image/png') no-repeat center; 
    height: 30px; 
    width: 41px; 
} 

我要寻找的是能够确定图像的宽度和高度,所以我可以做这样的事情的函数:

.folder { 
    background: inline-image("icons/home/folder.png", 'image/png') no-repeat center; 
    height: image-height("icons/home/folder.png", 'image/png'); 
    width: image-width("icons/home/folder.png", 'image/png'); 
} 

是否像这样的东西存在吗?

回答

8

发现这个http://compass-style.org/reference/compass/helpers/image-dimensions/

你已经猜到正确的函数名。

要使用它们,您需要安装指南针。

这将是这样的:

@import "compass/helpers"; 

.folder { 
    background: inline-image("icons/home/folder.png", 'image/png') no-repeat center; 
    height: image-height("icons/home/folder.png"); 
    width: image-width("icons/home/folder.png"); 
} 

顺便说一句,我会建议你使用精灵的图标: http://compass-style.org/reference/compass/helpers/sprites/

+0

只是不导入辅助功能。这真棒罗盘可以产生精灵。将转而转向精灵。谢谢您的帮助! – sissonb 2012-03-16 19:36:43

+0

我相信有一个失踪; @import“compass/helpers”之后。没有它就不会编译。 – 2014-03-22 20:38:29

+0

谢谢@ArthurAlvim – welldan97 2014-03-23 19:19:50