B
B
barsukovjke1g2019-08-06 17:39:43
css
barsukovjke1g, 2019-08-06 17:39:43

How to optimize SCSS recording?

Help describe the code more concisely. Confuses the ".list__link" class

.list {
  &__item {
    &:first-child {
      .list__link {
        font-weight: 700;
      }
    }
  }

  &__link {
      font-size: 1rem;
      text-transform: uppercase;
      letter-spacing: 2px;
      padding: .4rem 0;
      display: block;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Bogachev, 2019-08-06
@barsukovjke1g

Confuses the ".list__link" class

If you are confused by the repetition of list in the class name, then you can use saving the name in the that=this style from javascript:
.list {
    $b: &;

    &__item {
        &:first-child {
            #{$b}__link {
                // . . .
            }
        }
    }
}

But it can hardly be called a more readable option.
If the goal is still to make the code more digestible, then it may make sense to simply limit the nesting when writing styles (namely, the visual nesting of the code, and not the cascade), as they do in the same rscss:
.list {
    &__item {
        // . . .
    }

    &__link {
        // . . .
    }

    &__item:first-child &__link {
        // . . .
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question