Hover animation (version 2)

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

by Julien Roche

HTML

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

CSS

:root {
  --box-height: 4rem;
  --box-width: 15rem;
}

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: var(--box-height);
  line-height: 4rem;
  position: relative;
  text-align: center;
  width: var(--box-width);
}

.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__inside:before {
  border: 1px solid black;
  content: '';
  left: 0;
  height: 1rem;
  position: absolute;
  top: 0;
  transition: height 500ms ease;
  transition-property: height, border-color;
}

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

.box:hover:before,
.box:hover:after {
  border-color: red;
  width: calc(var(--box-width) - 2px);
}

.box:hover .box__inside:before,
.box:hover .box__inside:after {
  border-color: red;
  height: calc(var(--box-height) - 2px);
}