Files
30-seconds-of-code/snippets/button-border-animation.md
Angelos Chalaris 7e69307433 Update tags, expertise and descriptions across
Fix anything that was a bit out of place
2020-03-05 22:52:51 +02:00

917 B

title, tags
title tags
Button border animation animation,intermediate

Creates a border animation on hover.

<div class="button-border"><button class="button">Submit</button></div>
.button {
  background-color: #c47135;
  border: none;
  color: #ffffff;
  outline: none;
  padding: 12px 40px 10px;
  position: relative;
}

.button:before,
.button:after {
  border: 0 solid transparent;
  transition: all 0.25s;
  content: '';
  height: 24px;
  position: absolute;
  width: 24px;
}

.button:before {
  border-top: 2px solid #c47135;
  left: 0px;
  top: -5px;
}

.button:after {
  border-bottom: 2px solid #c47135;
  bottom: -5px;
  right: 0px;
}

.button:hover {
  background-color: #c47135;
}

.button:hover:before,
.button:hover:after {
  height: 100%;
  width: 100%;
}

Explanation

  • Use the :before and :after pseudo-elements as borders that animate on hover.

Browser support