$sizes: 1, 2, 3;
@each $size in $sizes {
.m-#{$size} {
margin: #{$size}rem;
}
}$sizes: 1, 2, 3; @each $size in $sizes { .m-#{$size} { margin: #{$size}rem; } }
@for $i from 1 through 4 {
.p-#{$i} {
padding: #{$i}rem;
}
}How many CSS classes will this generate?
@for $i from 1 through 4 { .p-#{$i} { padding: #{$i}rem; } }
$colors: red, green, blue;
@each $color in $colors {
.bg-#{$color}:hover {
background-color: $color;
}
}$colors: red, green, blue; @each $color in $colors { .bg-#{$color}:hover { background-color: $color; } }
@for $i from 1 through 3 {
.grid-cols-#{$i} {
display: grid;
grid-template-columns: repeat(#{$i}, 1fr);
}
}What will you see when applying
grid-cols-2 to a container with 4 items?@for $i from 1 through 3 { .grid-cols-#{$i} { display: grid; grid-template-columns: repeat(#{$i}, 1fr); } }
$btn-colors: primary, secondary;
@each $color in $btn-colors {
.btn-#{$color} {
background-color: map-get($colors, $color);
color: white;
}
}Note: The ARIA role is added in HTML, but you want the CSS classes to reflect the correct styling for accessibility focus states.
$btn-colors: primary, secondary; @each $color in $btn-colors { .btn-#{$color} { background-color: map-get($colors, $color); color: white; } }
