Last active
August 21, 2021 04:58
-
-
Save bagerathan/9bed25edd05b7edc23d89bfe83a64454 to your computer and use it in GitHub Desktop.
[Loop for preprocessors] #css #sass #less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://css-tricks.com/how-to-write-loops-with-preprocessors/ | |
//for | |
@for $i from 1 through 15 { | |
div { | |
&:nth-child(#{$i}) { | |
&::after { | |
content: "#{$i}"; | |
} | |
} | |
} | |
} | |
//while | |
$modifier: 0; | |
@while $modifier < 5 { | |
.padding-#{$modifier} { | |
padding: (10 * $modifier) + px; | |
} | |
$modifier: $modifier + 1; | |
} | |
//each | |
@each $value in (left, right, center, justify) { | |
.ta-#{$value} { | |
text-align: $value; | |
} | |
} | |
@each $value in (100, 300, 400, normal, 700, bold, 900) { | |
.fw-#{$value} { | |
font-weight: $value; | |
} | |
} | |
$colors: ( | |
"orange": #f4511e, | |
"blue": #1e88e5, | |
"red": #f44336 | |
); | |
@each $color, $i in $colors { | |
.bg-color-#{$color} { | |
background-color: $i; | |
} | |
} | |
@each $color, $i in $colors { | |
.color-#{$color} { | |
color: $i; | |
} | |
} | |
body { | |
padding: 20px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment