If you happen to’re in search of a primer on CSS specificity, we’ve obtained that. And should you’re making an attempt to get forward of the sport, try to be conscious of CSS Cascade Layers as effectively.
One of many methods to assist get a grasp of CSS specificity is considering phrases of “what beats what” or how sturdy the specificity is. Manuel Matuzovic has a useful interactive step-by-step demo. You retain clicking the “Add selector” button, and the CSS proven (and utilized to the web page) modifications with ever-increasingly-strong selectors utilized to the physique that change the background-color. On the finish, it veers into not-really-selectors trickery, like utilizing @keyframes to override issues.
Extra specificity apply
If you happen to loved the trickery on the finish, take a look at Francisco Dias’ A Specificity Battle!, an article we revealed a couple of years again that does a back-and-forth styling battle with nineteen steps “choosing” the identical ingredient to re-style it. CSS is cray generally.