Google analytics script

Latest jQuery CDN with code tiggling.

Wednesday, 14 November 2018

Any CSS class selector can have ID specificity

This will be a very short blog post. It's actually a life-saving hack that allows you to define a CSS class selector that has an ID specificity. You will know where it comes handy when you'll face such problem.

We were having a situation of our Angular app running inside a container and outer styles were interfering with our app styles. We already prefix all of our selectors by the container's CSS class name, but sometimes that's just not enough. And since scoped CSS isn't a thing any more, and we didn't want to refactor our app to have an ID container as there may be multiple instances of the same app in different containers (ID must be unique even though browsers are very loose when it comes to this), we wanted to raise our selectors' specificity anyway.