L
L
Lev Aleksandrov2022-01-22 13:46:35
BEM
Lev Aleksandrov, 2022-01-22 13:46:35

How to make BEM modifiers correctly?

There is a hat. The content in it (navigation links, SVG icons + logo) can be of different colors: either light or dark.
How to make modifiers correctly?
Create 2 modifiers header--light and header--dark and start from them using CSS selectors like this:
.header--dark .nav__link { color: #000; }
.header--light .nav__link { color: #fff; }
It is even readable: if the header is dark, then for the navigation links that are INSIDE this header we make a dark color (and by analogy for a light header).
Or create separate modifiers for each element inside the header?
Like .nav__link--light/.nav__link--dark or .socials__link--dark/.socials__link--light
Here we create a lot of modifiers that are unlikely to be useful anywhere else.

Please provide an example of the correct markup and styles for the header from screenshots (according to BEM)

61ebe046572c1799390354.png
61ebe04bd670d379194363.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Pershin, 2022-01-22
@h3ckphy

No nested selectors if it can be avoided, so either .nav__link--light/.nav__link--dark or
use css variables:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question