Hello everyone,
I’m wondering how specific should I make CSS selectors?
Should I include as many ancestor selectors as possible when selecting HTML elements?
Thank you for answering my question.
Yours faithfully.
Simon O.
Welcome to our community!
You should include those selectors that satisfy your creative intentions and desired style of your page.
Great question, even I had this in my mind till I found out about CSS BEM
Google css bem and read more about it.
With BEM
, your CSS is easy to build, maintain and refactor by you or any other developer who is going to own your project in future. I highly recommend this technique to use.
One more reason I liked BEM as React or any other JS framework makes you think on basic of component ( independant block / element of web page / app ) while building web app.
BEM
helps your thinking to align with component
No, as few as possible.
Keep the specificity flat (mainly using classes) and do not tie the styles to the DOM structure if you do not have to.
Thank you all for taking the time to answer my question.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.