Utilizando Sass para gerar cor e box-shadow em um loop

Henrique Melanda
Aug 1, 2018 · 2 min read
<header>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</header>
$elements: 10
@for $i from 0 to $elements
$elements: 10

@for $i from 0 to $elements
$red: ($i*10)+150
$green: (($i*10)+150)/2
$blue: (($i*10)+150)/2
#{$VARIABLE}
$elements: 10

@for $i from 0 to $elements
$red: ($i*10)+150
$green: (($i*10)+150)/2
$blue: (($i*10)+150)/2
header div:nth-child(#{$i})
background: rgb($red,$green,$blue)
width: 100%
height: 30px
box-shadow: 0 -1px #{($elements - $i)*2}px rgba(0,0,0,0.7)
header div:nth-child(0) {
background: #964b4b;
width: 100%;
height: 30px;
box-shadow: 0 -1px 20px rgba(0, 0, 0, 0.7);
}

header div:nth-child(1) {
background: #a05050;
width: 100%;
height: 30px;
box-shadow: 0 -1px 18px rgba(0, 0, 0, 0.7);
}

header div:nth-child(2) {
background: #aa5555;
width: 100%;
height: 30px;
box-shadow: 0 -1px 16px rgba(0, 0, 0, 0.7);
}

header div:nth-child(3) {
background: #b45a5a;
width: 100%;
height: 30px;
box-shadow: 0 -1px 14px rgba(0, 0, 0, 0.7);
}

header div:nth-child(4) {
background: #be5f5f;
width: 100%;
height: 30px;
box-shadow: 0 -1px 12px rgba(0, 0, 0, 0.7);
}

header div:nth-child(5) {
background: #c86464;
width: 100%;
height: 30px;
box-shadow: 0 -1px 10px rgba(0, 0, 0, 0.7);
}

header div:nth-child(6) {
background: #d26969;
width: 100%;
height: 30px;
box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.7);
}

header div:nth-child(7) {
background: #dc6e6e;
width: 100%;
height: 30px;
box-shadow: 0 -1px 6px rgba(0, 0, 0, 0.7);
}

header div:nth-child(8) {
background: #e67373;
width: 100%;
height: 30px;
box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.7);
}

header div:nth-child(9) {
background: #f07878;
width: 100%;
height: 30px;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.7);
}
Henrique Melanda

Written by

Entusiasta pelo estudo de novas tecnologias, por projetos open source e CSS Evangelista.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade