2012-10-31 48 views

回答

2

写在罗盘,image-heightimage-width是获得图像尺寸的功能。用你的精灵地图使用起来会是这个样子(警告,未经测试):当图像宽度()预计

// Assuming $my-sprites is your sprite map variable 
$map-path: sprite-path($my-sprites); 

$map-height: image-height($map-path); 
$map-width: image-width($map-path); 
+0

这似乎不再适用于最新版本的Sass(3.4)。 sprite-path将返回完整的文件系统路径,而image-width需要相对于images目录的路径。不知道他们为什么改变它。 –

-1

Ext.getBody()的getSize()让你的屏幕的高度和宽度,但我不认为你可以在SASS

1

在萨斯的最新版本(3.4)精灵路径()返回完整文件系统路径一个相对于images目录的路径。但有一个简单的解决方案:

sprite-width($sprite-map); 
sprite-height($sprite-map); 
0

可以使用神奇的尺寸功能<map>-sprite-height<map>-sprite-width得到一个单位值。

// Note: "my-icons" represents the folder name that contains your sprites. 

@import "my-icons/*.png"; 
$box-padding: 5px; 
$height: my-icons-sprite-height(some_icon); 
$width: my-icons-sprite-width(some_icon); 

.somediv { 
    height:$height + $box-padding; 
    width:$width + $box-padding; 
} 

查看official documentation了解更多详情。