S
S
SuperToster2021-08-13 20:17:52
Sass
SuperToster, 2021-08-13 20:17:52

What is the correct way to write this in SCSS?

<div class="parent">
  <div class="parent__child">
    parent
  </div>
</div>
<div class="parent parent--custom">
  <div class="parent__child">
    parent custom
  </div>
</div>

.parent {

}

.parent__child {
  background: gray;
}

@media (max-width: 777px) {
  .parent__child {
    background: orange;
  }

  .parent--custom .parent__child {
    background: red;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ankhena, 2021-08-13
@SuperToster

You can leave it as is.
Can be rewritten like this:

.parent__child {
  background: gray;
  @media (max-width: 777px) {
    background: orange;
    
    .parent--custom & {
    background: red;
  }
 }
}

it is possible like this:
.parent__child {
  background: gray;
  @media (max-width: 777px) {
    background: orange;
  }

  .parent--custom & {
    @media (max-width: 777px) {
      background: red;
    }
  }
}

And it's really good like this :
.parent__child {
  --color: gray;
  background: var(--color);
  @media (max-width: 777px) {
    --color: orange;
  }

  .parent--custom & {
    @media (max-width: 777px) {
      --color: red;
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question