@each $var in <list or map>
$var: 它代表了變數的名稱。 @each規則將 $var 每個專案在列表中使用 $var 值輸出樣式。
<list 或 map>: 這是 SassScript 表示式這將返回一個列表或對映。
<html> <head> <title>Control Directives & Expressions</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <p class="p_red">This is line one.</p> <p class="p_green">This is line two.</p> <p class="p_yellow">This is line three.</p> <p class="p_blue">This is line four.</p> </body> </html>
@each $color in red, green, yellow, blue { .p_#{$color} { background-color: #{$color}; } }
sass --watch C:\Ruby22-x64\style.scss:style.css
.p_red { background-color: red; } .p_green { background-color: green; } .p_yellow { background-color: yellow; } .p_blue { background-color: blue; }