Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change opacity of span within a on div:hover

Tags:

html

css

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?

like image 368
Michael Agarenzo Avatar asked Dec 04 '22 20:12

Michael Agarenzo


2 Answers

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:
like image 174
Nihal Avatar answered Dec 11 '22 17:12

Nihal


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>
like image 44
AKNair Avatar answered Dec 11 '22 15:12

AKNair