利用 SCSS 變數來設定背景顏色可以省去不少力氣,別再做個傻傻的碼農了^^
HTML:
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
SCSS:
$colors: (1: #664454, 2: yellow, 3: #00ff75, 4: #985544, 5: #665566);
@for $i from 1 through 5 {
div:nth-child(#{$i}){
text-align: center;
background-color: map-get($colors, $i);
}
}
HTML:
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
<div>AAAAA</div>
SCSS:
$colors: (1: #664454, 2: yellow, 3: #00ff75, 4: #985544, 5: #665566);
@for $i from 1 through 5 {
div:nth-child(#{$i}){
text-align: center;
background-color: map-get($colors, $i);
}
}
留言
張貼留言