Reputation: 27633
I've seen the following two notations on CSS pages, and they seem to work the same, is there a difference between them?
.ClassName a:hover
And:
a.ClassName:hover
Upvotes: 2
Views: 107
Reputation: 174624
The first modifies the hover
property for any link inside any element that has ClassName
applied.
The second is for any a
that has ClassName
applied, irrespective of any closing containers or tags.
Upvotes: 1
Reputation: 92803
.ClassName a:hover means anchor
inside .ClassName
. it's
HTML
<div class="ClassName ">
<a></a>
</div>
OR
a.ClassName:hover means .ClassName
with anchor
. It's
HTML
<a vlass="ClassName"></a>
Upvotes: 1
Reputation: 359776
Yes, there absolutely is a difference.
ClassName
.ClassName
.Upvotes: 1
Reputation: 33495
a.ClassName:hover
<a class="ClassName" href="#">fff</a>
.ClassName a:hover
<div class="ClassName">
<a href="#">fff</a>
</div>
First approach works only for <a>
elements with class ClassName
.
Second approach, class can be used for any element and if that element contains <a>
hover property will be processed.
Upvotes: 2
Reputation: 17457
Yes, there is a difference between them.
.ClassName a:hover
refers to any hovered anchor that is within an element with class="ClassName"
.
a.ClassName:hover
, however, refers to any hovered anchor that has class="ClassName"
.
There is lots of information regarding CSS Selectors at W3.org.
Upvotes: 4
Reputation: 12190
.ClassName a:hover //this applies to all child `a` elements of `ClassName`
<div class="ClassName">
<a>link</a>
</div>
a.ClassName:hover //this applies to the `a` elements that have `ClassName` class
<div>
<a class="ClassName">link</a>
</div>
Upvotes: 3