Thursday, June 11, 2020

css hack: win the specificity wars by doubling or tripling up at the classname

Heh, styled-components.com advanced page had a hack that I hadn't thought of but seems obvious in hindsite:

.red-bg.red-bg {
  background-color: red;
}

Like, make sure it REALLY is read even if there was a .green-bg class defined as well.

Well, beats !important, I guess?

No comments:

Post a Comment