L
L
Larisa2018-04-16 13:57:55
Sass
Larisa, 2018-04-16 13:57:55

How to rewrite scss correctly?

Please help me to correctly rewrite the lower example in scss

.test {
  &:hover { 
         /* вот сюда */
  }

  &__title, 
  &__name{
  color: green;
  }
}

/* вот этот код расписать в код выше   */
.test:hover .test__title,  
.test:hover .test__name{
  color: red;
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
display: block, 2018-04-16
@loratokareva

.test{
  $root: &;
  &:hover{
    #{$root}__title,
    #{$root}__name{
      color: red;
    }
  }
}

A
Alexey Sklyarov, 2018-04-16
@0example

.test {
  &:hover &__title { 
        
  }
  &:hover &__name{ 
        
  }
}

Or (but this is not a convenient option):
.test {
  &:hover { 
        .test__title{}
        .test__name{}
  }
}

UPD: And if you search on the stackoverflow, you can find out how it's done: https://stackoverflow.com/questions/34021910/bem-w...
UPD: For myself, and for you, I chose the most normal option implementations:
.test { 

    &__name {
        color: red;
    }

    &:hover & {
        &__name  {
            color: green;
        }   
    }
}

It is important not to forget about the ampersand after :hover, then it will be possible to write in the "familiar" form for you.

Z
zooks, 2018-04-16
@zooks

css2sass.herokuapp.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question