Skip to content Skip to sidebar Skip to footer

Border Animation Keyframes/css Animation

I have an animation that I want to achieve and I am not able to be getting it right. I've searched the internet and found some solutions, however they have a slight change in the a

Solution 1:

To achieve that you will need two divs so that you can create four different elements using its pseudo elements :before and :after and then use transition-delay to delay the transition

.main {
  width: 200px;
  height: 200px;
  position: relative;
}

.item {
  height: 100%;
}

.main:before,
.main:after,
.item:before,
.item:after {
  content: "";
  position: absolute;
  background: red;
}

.main:before {
  width: 2px;
  height: 0;
  bottom: 0;
  left: 0;
}

.main:after {
  height: 2px;
  width: 0;
  top: 0;
  left: 0;
}

.item:before {
  width: 2px;
  height: 0;
  top: 0;
  right: 0;
}

.item:after {
  height: 2px;
  width: 0;
  right: 0;
  bottom: 0;
}

.main:hover:before {
  height: 100%;
  transition: all .5s linear;
}

.main:hover:after {
  width: 100%;
  transition: all .5s linear .5s;
}

.main:hover.item:before {
  height: 100%;
  transition: all .5s linear 1s;
}

.main:hover.item:after {
  width: 100%;
  transition: all .5s linear 1.5s;
}
<divclass="main"><divclass="item">
    Some Content
  </div></div>

Post a Comment for "Border Animation Keyframes/css Animation"