Hover animation

inspired by https://twitter.com/CodePen/status/1088653707380736000

by Julien Roche

HTML

<body>
  <div class="box">Hover me</div>
</body>

CSS

html,
body {
  background-color: yellow;
  border: none;
  color: black;
  height: 100%;
  margin: 0 0 0 0;
  padding: 0 0 0 0;
}

body {
  align-items: center;
  display: flex;
  justify-content: center;
}

.box {
  flex: 0 0 auto;
  font-size: 3rem;
  font-weight: bolder;
  height: 4rem;
  line-height: 4rem;
  position: relative;
  text-align: center;
  width: 15rem;
}

.box:after {
  border: 1px solid black;
  content: '';
  bottom: 0;
  position: absolute;
  right: 0;
  transition: width 500ms ease;
  transition-property: width, border-color;
  width: 3rem;
}

.box:before {
  border: 1px solid black;
  content: '';
  left: 0;
  position: absolute;
  transition: width 500ms ease;
  transition-property: width, border-color;
  top: 0;
  width: 3rem;
}

.box:hover:before, .box:hover:after {
  border-color: red;
  width: 15rem;
}