css实现边框围绕内容旋转特效

237 阅读1分钟
          <div class="item-container">
            <div class="title">合格品数量</div>
            <el-tag >{{item.value}}</el-tag>
          </div>
  
  
  
  
.item-container {
  position: relative;
  width: 120px; // 注意
  // color: #fff;
  border-radius: 10px;
  transition: all 0.3s;
  cursor: pointer;
  &:hover {
    filter: contrast(1.1);
  }
  &:active {
    filter: contrast(0.9);
  }
  &::before,
  &::after {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    border: 2px solid gold;
    transition: all 0.5s;
    animation: clippath 3s infinite linear;
    border-radius: 10px;
  }

  &::after {
    animation: clippath 3s infinite -1.5s linear;
  }
}
@keyframes clippath {
  0%,
  100% {
    clip-path: inset(0 0 98% 0);
  }

  25% {
    clip-path: inset(0 98% 0 0);
  }
  50% {
    clip-path: inset(98% 0 0 0);
  }
  75% {
    clip-path: inset(0 0 0 98%);
  }
}

20230731_113241.gif