【CSS】How to make a line loop along a border on a button border(Demo page)

※Please check using Developer tools

DummyText

Sponsored links

CSS

.block {
  margin: 70px auto 0;
}

.button {
  position: relative;
  display: block;
  width: 300px;
  height: 50px;
  overflow: hidden;
  line-height: 50px;
  margin: 0 auto;
  box-sizing: border-box;
  text-align: center;
}

.button:before,
.button:after {
  position: absolute;
  content: "";
  display: block;
  width: 100%;
  height: 1px;
  background: #000;
  z-index: 2;
}

.button:before {
  left: 0px;
  top: 0px;
  animation: move-top 2.5s cubic-bezier(0.6, 0.06, 0.68, 0.2) 0s infinite;
}

.button:after {
  right: 0px;
  bottom: 0px;
  animation: move-bottom 2.5s cubic-bezier(0.6, 0.06, 0.68, 0.2) 0s infinite;
}

.inner {
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  transition: background .15s linear;
}

.inner:before,
.inner:after {
  content: "";
  display: block;
  width: 1px;
  height: 100%;
  background: #000;
  position: absolute;
  z-index: 2;
}

.inner:before {
  left: 0px;
  top: 0px;
  animation: move-left 2.5s cubic-bezier(0.6, 0.06, 0.68, 0.2) 0s infinite;
}
.inner:after {
  right: 0px;
  bottom: 0px;
  animation: move-right 2.5s cubic-bezier(0.6, 0.06, 0.68, 0.2) 0s infinite;
}

.border {
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  border: 1px solid #000;
  box-sizing: border-box;
  opacity: .4;
}

@keyframes move-top {
  0% {
    transform: translate3d(-100%, 0, 0);
  }
  50% {
    transform: translate3d(0%, 0, 0);
  }
  75% {
    transform: translate3d(100%, 0, 0);
  }
  100% {
    transform: translate3d(100%, 0, 0);
  }
}

@keyframes move-bottom {
  0% {
    transform: translate3d(100%, 0, 0);
  }
  50% {
    transform: translate3d(0%, 0, 0);
  }
  75% {
    transform: translate3d(-100%, 0, 0);
  }
  100% {
    transform: translate3d(-100%, 0, 0);
  }
}

@keyframes move-left {
  0% {
    transform: translate3d(0%, 100%, 0);
  }
  50% {
    transform: translate3d(0%, 100%, 0);
  }
  100% {
    transform: translate3d(0%, -100%, 0);
  }
}

@keyframes move-right {
  0% {
    transform: translate3d(0%, -100%, 0);
  }
  50% {
    transform: translate3d(0%, -100%, 0);
  }
  100% {
    transform: translate3d(0%, 100%, 0);
  }
}

@media screen and (max-width:640px){
  a {
    width: 80%;
  }
}