.classname vs .clasname #id vs .classname#id
.classname
:This selector targets all elements with the class
classname
.Example:
Both the
<div>
and the<p>
elements will have their text color set to green because they both have the classclassname
.
.classname #id
:This selector targets an element with the id
id
that is a descendant of an element with the classclassname
.Example:
Only the first
<p>
with the idid
will have its text color set to blue because it is a descendant of an element with the classclassname
.
.classname#id
(without a space between the class and id):
This selector targets an element that has both the class
classname
and the idid
.Example:
Only the first
<div>
will have its text color set to blue because it has both the classclassname
and the idid
.
Last updated