1

I have a text with two emojis
I want to flip one emogi with another using css.

When the first emogi is shown I want to the second emoji to be hidden. So they kinda indefinitely replacing each other.

I found here a great example how to make text blink

    .blink {
      animation: blinker 1s step-start infinite;
    }
    
    @keyframes blinker {
      50% {
        opacity: 0;
      }
    }
    
    <div class="blink"></div>

So how would you show the second emogi while the first one is hidden?

Sergino
  • 10,128
  • 30
  • 98
  • 159

3 Answers3

4

You can use a pseudo-element:

.blink::before {
  content: "";
  animation: blinker 1s linear infinite alternate;
}

@keyframes blinker {
  0% {
    content: "";
  }
  50% {
    opacity: 0%;
  }
  100% {
    content: "";
  }
}
<div class="blink"></div>
iz_
  • 15,923
  • 3
  • 25
  • 40
2

.emoji-cont {
  position: relative;
}

.blink, .blink-2 {
    position: absolute;
}

.blink {
  animation: blinker 1s infinite;
}

.blink-2 {
  animation: blinker 1s .5s infinite;
}

@keyframes blinker {
  50% {
    opacity: 0;
  }
}
<div class="emoji-cont">
  <div class="blink"></div>
  <div class="blink-2"></div>
</div>
Sameer
  • 4,758
  • 3
  • 20
  • 41
0

You can set the pseudo-element display: inline-block, to open up more animation options.

Here we use transform: scaleX() to create a flip effect, as if the emoji has different sides (front and back).

Useful if you're were looking for a different way to transition between the two emojis; rather than a simple fade.

.blink::before {
  content: "";
  display: inline-block;
  animation: blinker 1s linear infinite alternate;
}

@keyframes blinker {
  0% {
    content: "";
    transform: scaleX(1);
  }
  50% {
    transform: scaleX(0);
  }
  100% {
    content: "";
    transform: scaleX(1);
  }
}
<div class="blink"></div>
joewoodio
  • 11
  • 3