【发布时间】:2023-03-18 19:52:01
【问题描述】:
按照关于神奇维度函数的Spriting with Compass 页面说明,我正在尝试使用类似的方法设置每个精灵的大小:
.top-bar-section {
ul {
& > li {
// Generate the sprite map.
$menu_icons-sprite-map: sprite-map("menu_icons/*.png", $layout: smart);
// Set the background image.
& > a:before {
background: sprite-url($menu_icons-sprite-map) 0 0 no-repeat;
display: inline-block;
content: "";
@include background-size(cover);
}
// Set the background position for each sprite.
$menu_icons-sprite-names: sprite-names($menu_icons-sprite-map);
@each $name in $menu_icons-sprite-names {
&.menu_icons-#{$name} > a:before {
background-position: sprite-position($menu_icons-sprite-map, $name);
$height: menu_icons-sprite-height($name);
$width: menu_icons-sprite-width($name);
height: $height;
width: $width;
}
}
}
}
但是,生成的 CSS 看起来像这样:
...
.top-bar .top-bar-section ul > li.menu_icons-omino_001 > a:before {
background-position: 0 0;
height: menu_icons-sprite-height(omino_001);
width: menu_icons-sprite-width(omino_001);
}
.top-bar .top-bar-section ul > li.menu_icons-omino_002 > a:before {
background-position: 0 -64px;
height: menu_icons-sprite-height(omino_002);
width: menu_icons-sprite-width(omino_002);
}
...
好像不是指南针创造的神奇功能:我错过了什么吗?
【问题讨论】: