Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate image and set hover CSS

I want to make the following animation:

enter image description here

One div with 2 same arrows and on hover first arrow should move on left/right. I tried to do it, but it unsuccessfully. I'm setting background with 2 images, but how I can set animation for 1 of the images like the gif?

.arrow-right2 {
    content: "";
    background: transparent url(https://i.imgur.com/u7cYXIo.png) 0 -185px no-repeat, transparent url(https://i.imgur.com/u7cYXIo.png) 0 -185px no-repeat;
    height: 35px;
    position: absolute;
    top: -5%;
    left: 0;
    width: 35px;
}
like image 298
Stephanie Kostova Avatar asked Oct 20 '25 15:10

Stephanie Kostova


1 Answers

Try to use 2 different divs with the same arrows, with position absolute and use this to overlap the two arrows. If you can, use a single image, not a sprite. Then apply the effect on hover on one of the images.

body {
  background: red;
   display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 50px;
  height: 50px;
  position: relative;
}
.arrow1 {
  background: url('https://i.imgur.com/u7cYXIo.png') no-repeat -17px -199px;
	width: 12px;
	height: 24px;
  display: block;
  left: 0;
  position: absolute;
}
.arrow2 {
  background: url('https://i.imgur.com/u7cYXIo.png') no-repeat -17px -199px;
	width: 12px;
	height: 24px;
  display: block;
  position: absolute;
  transition: all 0.4s;
  left: 0;
}
.arrow2:hover {
  left: -10px;
  transition: all 0.4s;
}
<div class="container">
  <div class="arrow1">
  </div>
  <div class="arrow2">
  </div>
</div>
like image 143
Gabriel B. Avatar answered Oct 23 '25 06:10

Gabriel B.