by CuriouslyC · 3y ago · 0 comments
Style classes are IMO the neatest way to inject styles, having elements get styles based on html structure makes code brittle and hard to reason about. If you need an example of this try playing with bootstrap forms.
And I did not say to base styles on html structure - you are correct, that is brittle and actually one of the things I often ask about in FE interviews as a way of determining skill level. I said that good html structure makes CSS much easier, if your structure is bad, it can significantly compound the amount of CSS needed in order to achieve the desired outcome. So I believe there is a significant distinction in those two statements.
<div class="unique-component-name">
<input class="unique-component-name-input" />
<p class="unique-component-name-text">Blah</p>
</div>
<div class="unique-component-name unique-component-name-variant1">
...
.unique-component-name {
...
The cascading in HTML makes the thing that should be easy, creating variants with slight tweaks the most painful thing.