CSS3邊框動態環繞效果

admin發表於2018-03-23

下面分享一段程式碼例項,它實現了邊框環繞效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
.antzone, .antzone::before, .antzone::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}
.antzone {
  width: 200px;
  height: 200px;
  margin: auto;
  color: #69ca62;
  box-shadow: inset 0 0 0 1px rgba(105, 202, 98, 0.5);
}
.antzone::before, .antzone::after {
  content: '';
  z-index: -1;
  margin: -5%;
  box-shadow: inset 0 0 0 2px;
  animation: clipMe 8s linear infinite;
}
.antzone::before {
  animation-delay: -4s;
}
@keyframes clipMe {
  0%, 100% {
    clip: rect(0px, 220.0px, 2px, 0px);
  }
  25% {
    clip: rect(0px, 2px, 220.0px, 0px);
  }
  50% {
    clip: rect(218.0px, 220.0px, 220.0px, 0px);
  }
  75% {
    clip: rect(0px, 220.0px, 220.0px, 218.0px);
  }
}
</style>
</head>
<body>
  <div class="antzone"></div>
</body>
</html>

上面程式碼實現了邊框環繞效果,下面介紹一下它的實現過程。

相關文章