Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

html - How to make hover effect work on part of an image

I’m trying to make a hover image appear over an image but only when I hover over a certain area of the image, can’t seem to get an area map to fit into the code I already have. Help would be much appreciated.

.overlay-image .hover {
  position: relative;
  left: 1084;
  height: 2;
  width: 3;
  transform: rotate(341deg);
  opacity: 3;
  transition: .8s ease;
}

.maine .hover {
  position: absolute;
  width: 125;
  height: 150;
  top: 58;
  left: 1084;
}

.overlay-image .hover {
  position: absolute;
  top: 58;
  height: 2px;
  width: 3px;
  opacity: 0;
  transition: .8s ease;
}


/* New overlay appearance on hover */

.overlay-image:hover .hover {
  opacity: 1;
}
<div class="overlay-image">
  <a href="LINK_URL">
    <img class="image" src="https://i.imgur.com/bn03Ndw.png" alt="Alt text" />
    <div class="normal">
      <div class="text">Image + text ORIGINAL
      </div>
    </div>
    <div class="hover" align="1084,58">
      <img class="image" src="https://i.imgur.com/lN2UnH2.png" alt="Alt text hover" width="125" height="150" />
      <div class="text"></div>
    </div>
  </a>
</div>
question from:https://stackoverflow.com/questions/65906565/how-to-make-hover-effect-work-on-part-of-an-image

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Using a div container:

https://jsfiddle.net/9cgorq1z/4/

.image.show {
  opacity: 0;
}

.cotainer-hover {
  background: red;
  width: 150px;
  height: 150px;
  position: absolute;
  opacity: .2;
}

.cotainer-hover:hover ~ .image.show {
   opacity: 1;
}
<div class="cotainer-hover"></div>
<img class="image original" src="https://i.imgur.com/bn03Ndw.png" width="300"/>
<img class="image show" src="https://i.imgur.com/lN2UnH2.png" width="125"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...