Billa Billa - 2 days ago 4
CSS Question

Can I use DIV class and ID together in CSS?

Can I use DIV Class and ID together in CSS?
For example:

<div class="x" id="y">
--
</div>

Answer

Yes, yes you can.

#y.x {
 /* will select element of id="y" that also has class="x" */
}

Similarly:

.x#y {
 /* will select elements of class="x" that also have an id="y" */
}

Incidentally this might be useful in some use cases (wherein classes are used to represent some form of event or interaction), but for the most part it's not necessarily that useful, since ids are unique in the document anyway. But if you're using classes for user-interaction then it can be useful to know.

Comments