【发布时间】:2015-05-05 06:37:33
【问题描述】:
由于我是 sass (SCSS) 的新手,我的野心目前似乎超出了我的能力。有人可以帮助我完成以下任务。
背景
我们目前有一个具有两种不同文件格式的图标系统;一个是PNG,另一个是SVG。我们的一些图标有两种文件类型,一些有 PNG 或 SVG。我希望能够单独列出它们。
这是我的 SCSS 变量映射。
$image-path: "http://www.mywebsite.com/assets/img/icons";
$icons-map: (
tick: (
filename: icons_tick,
has-png: true,
has-svg: false,
),
secure: (
filename: icons_secure,
has-png: true,
has-svg: true,
),
checkout: (
filename: icons_checkout,
has-png: false,
has-svg: true,
),
);
以及我如何尝试将它们列出...
/* Standard (PNG) Icons */
@each $icon-type, $icon-file in $icons-map {
@if $has-png == "true" {
.icon-#{$icon-type}:after {
background-image: url('#{$image-path}/png/#{$filename}.png');
}
}
}
/* Advanced SVG icons (progressive enhancement for newer mobiles, retina-style displays, etc) */
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and ( min-device-pixel-ratio: 2),
only screen and ( min-resolution: 192dpi),
only screen and ( min-resolution: 2dppx) {
@each $icon-type, $icon-file in $icons-map {
@if $has-svg == "true" {
.icon.#{$icon-type}:after {
background-image: url('#{$image-path}/svg/#{$filename}.svg');
}
}
}
}
唯一的问题是它似乎没有计划......有什么想法我会出错吗?我认为这是我在嵌套地图上循环的方式,或者是我设置“if”语句的方式。
我会预计输出是这样的;
/* Standard (PNG) Icons */
.icon.tick {
background-image: url('http://www.mywebsite.com/assets/img/icons/png/icons_tick.png');
}
.icon.secure {
background-image: url('http://www.mywebsite.com/assets/img/icons/png/icons_secure.png');
}
/* Advanced SVG icons (progressive enhancement for newer mobiles, retina-style displays, etc) */
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and ( min-device-pixel-ratio: 2),
only screen and ( min-resolution: 192dpi),
only screen and ( min-resolution: 2dppx) {
.icon.secure {
background-image: url('http://www.mywebsite.com/assets/img/icons/svg/icons_secure.svg');
}
.icon.checkout {
background-image: url('http://www.mywebsite.com/assets/img/icons/svg/icons_checkout.svg');
}
}
不断收到 $has-png 和 $has-svg 是未定义变量的错误。
感谢您的帮助。
【问题讨论】:
标签: css if-statement sass each