- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I am wondering what if any the difference between defining a class like “.class” versus “tag.class” ie. “IMG.class”. I usually use the “tag.class” style as it is easier to read the CSS file imo.
Is there any advantage / disadvantage to either was of doing it.
I suppose one drawback of using a selector like img.class
is that it has a higher specificity than simply .class
, which could cause unforeseen conflicts as you add more css.
Also, sometimes it’s good to have a class that is not based on a specific type of element. For example if you have a class like .red_text
, you could apply it to spans, headers, paragraphs etc…
Well, those selectors are actually totally different.
div.class {
color:blue;
}
Will only, obviously, affect div
elements. If you were to use .class
instead, it will affect every element with the class.
It’s also a different level of specificity. Suppose you have the following:
div.class {
color:red;
}
.class {
color:blue;
}
The applied style will be color:red
since the selector is more specific.
edit: Ah, was too slow
Thanks for the quick replies