Suppose there is such a markup:
<header id="header"> <div class="header-top"> <div class="callus">+0 000 0000 00</div> </div> </header> And there are several options:
.callus {} #header .callus {} .header-top .callus {} #header .header-top .callus {} I usually watch the first option on sites. But it seems to me that this is not a good idea for 2 reasons:
- Great chance of conflict with future modifications (another person will have to have fun with your styles, even if he just wants to add, and not change something)
- When adding a news / post to the site, the visual editor can add some kind of its own design or tags (which I personally encountered many times).
The second option , like, specifies: we need the elements in the header. But with a large level of nesting, the engine makes a long way from each of the elements with the callus class to the very top, until it finds an element with id header
The third option is something between 1 and 2. It seems to solve the problem, but the chance of error remains.
The fourth option is called redundant selectors , if not mistaken. And yes, this is bad.
What advise about the selectors? The fact that class names should reflect the essence of the element as much as possible is understandable. And what about concretization, reducing the likelihood of errors and performance?
I like the BEM system, but not everything is clear. I would be grateful if someone would lead css-styles for such markup:
<header class="header"> <img class="logo"> <form class="search-form"> <input type="input"> <button type="button"></button> </form> <ul class="lang-switcher"> <li class="lang-switcher__item"> <a class="lang-switcher__link" href="url">en</a> </li> <li class="lang-switcher__item"> <a class="lang-switcher__link" href="url">ru</a> </li> </ul> </header> Why, for example, logo instead of header__logo ?