JSFiddle - React, Tailwind, and code Playground
HTML
<div id="anim">
<div>
<h1>Hover me!</h1>
</div>
</div>
CSS
body {
margin: 0;
padding: 0;
height: 100vh;
width: 100vw;
background-color: lightgrey;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
#anim {
display: inline-block;
position: relative;
}
#anim div {
display: inline-block;
position: relative;
}
#anim div h1 {
margin: 0;
font-family: arial;
line-height: 30px;
padding: 10px;
color: black;
}
#anim::before, #anim::after, #anim div::before, #anim div::after {
content:"";
position: absolute;
background-color: lightgrey;
-webkit-animation: 1s forwards;
animation: 1s forwards;
}
#anim::before, #anim::after {
height: 2px;
}
#anim div::before, #anim div::after {
width: 2px;
}
#anim::before, #anim div::before {
top: 0;
left: 0;
}
#anim::after, #anim div::after {
bottom: 0;
right: 0;
}
#anim:hover::before, #anim:hover::after {
width: 100%;
-webkit-animation-name: t-b;
animation-name: t-b;
}
#anim:hover div::before, #anim:hover div::after {
height: 52px;
-webkit-animation-name: r-l;
animation-name: r-l;
}
#anim:hover div h1 {
border: 2px black solid;
}
@-webkit-keyframes t-b {
to {
width: 0;
}
}
@keyframes t-b {
to {
width: 0;
}
}
@-webkit-keyframes r-l {
to {
height: 0;
}
}
@keyframes r-l {
to {
height: 0;
}
}