2

Hi I want to change the text opacity when hovering a image. I tried to use this but it doesn't work:

HTML:

<div class="text">
        SOME TEXT
    </div>

<img src="image1.jpg" class="first-image">

CSS:

.text {
opacity: 0;
}

.first-image:hover {
text.opacity: 1;
}
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701

3 Answers3

1

If you want to do it the way you was doing it with pure CSS, revised snippet below:

<dic class="first-image">
 <img src="image1.jpg" alt="first-image"/>
 <div class="text">SOME TEXT</div>
</div>

..

.text {
   opacity: 0;
  }

  .first-image:hover > div{
     opacity: 1;
   }
yardie
  • 1,583
  • 1
  • 14
  • 29
0

In jquery, grab the class of the image, and on hover, change the opacity of the text class to 1.

 $('.first-image').hover(function(){
  $('.text').css('opacity', '1');
 });
amespower
  • 907
  • 1
  • 11
  • 25
0
  1. Use jQuery to listen for a mouseenter event on the image. When that event is fired, add a class (like active) to the <div class="text"> element so it would look like <div class="text active">. On the exit of the mousenter event (mouseleave), make sure to remove the active class. OR you can modify the css through jQuery directly.

  2. Add css to change the text opacity:
    .text.active { opacity: 0.5; }

Alex
  • 5,298
  • 4
  • 29
  • 34