JSFiddle - React, Tailwind, and code Playground
HTML
<div class="bobbing text">Bobbing</div>
<div class="bobbing image"></div>
CSS
body {
background-color: #ccc;
}
.bobbing {
position: absolute;
animation-name: bobbingAnim;
animation-duration: 4s;
animation-iteration-count: infinite;
animation-play-state: running;
-webkit-animation-name: bobbingAnim;
-webkit-animation-duration: 4s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-play-state: running;
}
.bobbing.text {
font-size: 50px;
color: #000;
left: 30px;
top: 30px;
}
.bobbing.image {
left: 30px;
top: 150px;
background: url(http://placehold.it/300x100/aa0000&text=Bobbing+image) 50% 50% no-repeat;
width: 310px;
height: 110px;
}
@keyframes bobbingAnim {
0% {
transform: translate(0px, 0px);
animation-timing-function:ease-in-out
}
50% {
transform: translate(0px, 12px);
animation-timing-function:ease-in-out
}
100% {
transform: translate(0px, 0px);
animation-timing-function:ease-in-out
}
}
@-webkit-keyframes bobbingAnim {
0% {
-webkit-transform: translate(0px, 0px);
-webkit-animation-timing-function:ease-in-out
}
50% {
-webkit-transform: translate(0px, 12px);
-webkit-animation-timing-function:ease-in-out
}
100% {
-webkit-transform: translate(0px, 0px);
-webkit-animation-timing-function:ease-in-out
}
}