Reputation: 239
I would like to change the opacity of a span
within an a
when the div
all of this is within is hovered.
HTML:
<div id="about">
<a style="text-decoration: none;" href="/about"><h1>ABOUT ME</h1><br><span class="hover-text">test</span></a>
</div>
CSS:
.hover-text {
opacity: 0;
}
#about:hover {
change .hover-text opacity to 1
}
Is this possible to do with pure CSS?
Upvotes: 4
Views: 1158
Reputation: 378
.about:hover>.hover-text {
opacity: 0;
}
'>' is used to apply css for that particular child class
Upvotes: 2
Reputation: 12969
it's invalid to place a block-level element like
h1
inside an inline element likea
.
For fix your case, use this code:
#about:hover .hover-text {
opacity: 1;
}
.hover-text {
opacity: 0;
}
#about:hover .hover-text {
opacity: 1;
}
<div id="about">
<a style="text-decoration: none;" href="/about">
<h1>ABOUT ME</h1>
<br>
<span class="hover-text">test</span>
</a>
</div>
Upvotes: 2
Reputation: 230
.hover-text {
opacity: 0;
}
#about a:hover .hover-text {
opacity: 1;
}
Upvotes: 2
Reputation: 63
Your question seems a little confusing. From what I can tell, when you hover #about
, you want to hide .hover-text
.hover-parent:hover .hover-text{
opacity: 0;
}
This will work for more than just the about div (just make sure you add the .hover-parent
class)
Upvotes: 0
Reputation: 1587
Yes, Its possible. Just use the correct selector
.hover-text {
opacity: 0;
}
#about:hover .hover-text {
opacity: 1;
}
<div id="about">
<a style="text-decoration: none;" href="#"><h1>ABOUT ME</h1><br><span class="hover-text">test</span></a>
</div>
Upvotes: 2
Reputation: 70
Is this what you're looking for?
#about:hover .hover-text{
opacity: 1;
}
Upvotes: 1
Reputation: 5344
it only works on child element.
For example .about class has child span then it will work
.about:hover .hover-text {
opacity: 0;
}
.about{
border:1px solid black;
}
.hover-text{
opacity: 0;
font-size:30px;
}
.about:hover .hover-text {
opacity: 1;
}
<div class="about">
<a style="text-decoration: none;" href="/about"><h1>ABOUT ME</h1><br><span class="hover-text">test</span></a>
</div>
CSS:
Upvotes: 5