Pulsating ring animation with CSS

余生颓废 提交于 2019-12-01 09:16:46

Here's a general solution using CSS flexbox, transform and pseudo-elements.

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: lightyellow;
  height: 100vh;
  margin: 0;
}
#container {
  display: flex;
  align-items: center;
  justify-content: center;
}
.sphere {
  display: flex;
  background: lightblue;
  border-radius: 300px;
  height: 100px;
  width: 100px;
}
#container::after {
  display: flex;
  background: lightpink;
  border-radius: 300px;
  height: 250px;
  width: 250px;
  animation: pulsate 2.5s ease-out;
  animation-iteration-count: infinite;
  opacity: 0.0;
  content: "";
  z-index: -1;
  margin: auto;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
@keyframes pulsate {
  0% {
    transform: scale(0.1, 0.1);
    opacity: 0.0;
  }
  50% {
    opacity: 1.0;
  }
  100% {
    transform: scale(1.2, 1.2);
    opacity: 0.0;
  }
}
<div id="container">
  <div class="sphere"></div>
</div>

jsFiddle

Also see this awesome solution by @harry: How to create a pulsing glow ring animation in CSS?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!