Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are CSS selectors without properties of any effect?

Tags:

css

I got a maintenance job and there is a huge CSS file, in which I found a lot of things like the following:

.xxxx {}

That is, a selector with absolutely nothing in it. I think they are useless, but there are so many of them I start to doubt myself. Am I right that they can be removed safely? Or they actually are doing something and I should keep them?

like image 662
Terry Chang Avatar asked Aug 31 '15 09:08

Terry Chang


Video Answer


1 Answers

I'd say it's probably the worst design in history (or a stronger contender to the title...) but it could be used.

See below:

document.styleSheets[0].cssRules[0].style.setProperty('color', 'red');
.randomClass {}
<div class="randomClass">No styling?</div>

You can acces, process, and even modify stylesheets. Even if a selector is empty of styles, that can be modified using code.

So, it's probably very safe to remove, but if you want to be 100% certain, either leave it there, or go through all possible code branches.

like image 186
Amit Avatar answered Nov 15 '22 13:11

Amit