A
A
Artyom2020-02-07 14:30:50
Sass
Artyom, 2020-02-07 14:30:50

What is the best way to write styles in scss?

If I have such html

<div class="result-container">
  <img src="/src/views/AppVIew/images/SM_Icon_Youtube.png" alt="" class="result-container-image">
  <a href="https://www.youtube.com/watch?v=wiTujJZ4G0k" class="result-container-link"></a>
  <p class="result-container-author">test user</p>
  <p class="result-container-date">test date</p>
  <p class="result-container-viewCount"> test view count</p>
</div>

What is the best way to write SCSS to it? Should each element nested in result-container have its own class, or can you just set styles through nesting, as I did below?
.result-container {
  max-width: 200px;
  img {
    max-width: 100%;
  }
  p {
    color:red;
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Popov, 2020-02-08
@groog

Look towards BEM
https://ru.bem.info/
in particular
https://ru.bem.info/methodology/naming-convention/

S
Sergey Kupletsky, 2020-02-24
@zavoloklom

Depends on the methodology you want to follow.
In addition to the mentioned Daniil Popov BEM, you can also pay attention to:
- Atomic CSS
- MCSS
- SMACSS
You can first read an overview of these methodologies on Habré:
https://habr.com/ru/post/256109/
And choose what you need like it and fit better.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question