您嘗試生成的課程無效。通過驗證運行它會給這個錯誤:
In CSS1, a class name could start with a digit (".55ft"), unless it was a dimension (".55in"). In CSS2, such classes are parsed as unknown dimensions (to allow for future additions of new units) To make "22ltr-porche" a valid class, CSS2 requires the first digit to be escaped ".\32 2ltr-porche" [22ltr-porche]
所以,我們需要逃避領先的數字像它說:
@function escape_leading_numbers($s) {
$first-char: str_slice(#{$s}, 0, 1);
$found: index('1' '2' '3' '4' '5' '6' '7' '8' '9' '0', $first-char);
@return if($found, unquote(str-insert(str-slice(#{$s}, 2), "\\3#{$first-char} ", 1)), $s);
}
$name: '007';
.#{escape_leading_numbers($name)} {
color: red;
}
@each $car in
bmwwhite
hondared
22ltr-porche
30ltr-cossworth
{
.#{escape_leading_numbers($car)} {
background:url(/img/cars/#{$car}.jpg) no-repeat
}
}
輸出:
.bmwwhite {
background: url(/img/cars/bmwwhite.jpg) no-repeat;
}
.hondared {
background: url(/img/cars/hondared.jpg) no-repeat;
}
.\32 2ltr-porche {
background: url(/img/cars/22ltr-porche.jpg) no-repeat;
}
.\33 0ltr-cossworth {
background: url(/img/cars/30ltr-cossworth.jpg) no-repeat;
}
http://sassmeister.com/gist/e07d3fd4f67452412ad0
該輸出是[class =「bmwwhite」] { background: 因此輸出在.css文件中是錯誤的:/ –
@ReneZammit這不正常嗎? – miphe
不,它不是因爲輸出應該是.bmwwhite {background:............} 而是輸出是這樣來的[class =「bmwwhite」] {background:..... ..} –