this post was submitted on 16 Aug 2023
2 points (100.0% liked)

CSS

477 readers
1 users here now

founded 1 year ago
MODERATORS
2
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/css
 

For a project, I had to compile SCSS code to CSS. Everything seemed to work, except for a @for loop similar to this :

$base-color: #036;

@for $i from 1 through 3 {
  ul:nth-child(3n + #{$i}) {
    background-color: lighten($base-color, $i * 5%);
  }
}

This loop hasn't been compiled at all to CSS, as CSS does not loop though selectors. But is there a way to loop this code with JavaScript ?

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 1 points 1 year ago (1 children)
[โ€“] tinker_james 1 points 1 year ago

I just did a really silly loop (I'm on my phone) and it seemed to work.

@for $t from 1 through 2 {
  .a-#{$t} {
    color: red;
   }
}