JSFiddle - React, Tailwind, and code Playground
by Morgan Gilroy
May 16, 2017
HTML
<h1>CSS Border Animation</h1>
<div id="testBox" class="testBox borderTransition">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacus purus, interdum in sem sed, dapibus lobortis erat.
</div>
<BR />
<div id="testBox2" class="testBox borderAnimation">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacus purus, interdum in sem sed, dapibus lobortis erat.
</div>
<BR />
<div id="testBox3" class="testBox borderAnimation2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacus purus, interdum in sem sed, dapibus lobortis erat.
</div>
CSS
html {
background: #fafafa;
}
body {
color: #4b507a;
font: 300 24px/1.5 Lato, sans-serif;
margin: 1em auto;
max-width: 36em;
padding: 1em 1em 2em;
text-align: center;
}
h1 {
font-weight: 300;
font-size: 2.5em;
}
.testBox {
border-radius: 3px;
background-color: #EaEaEa;
box-shadow: inset 0 0 0 2px #4286f4;
min-height: 100px;
transition: 0.25s;
padding: 10px;
}
.testBox:hover {
background-color: #dadada
}
.borderTransition {
border: 0;
box-sizing: border-box;
position: relative;
}
.borderTransition::before,
.borderTransition::after {
box-sizing: inherit;
content: '';
position: absolute;
border: 2px solid transparent;
width: 0px;
height: 0px;
}
.borderTransition::before {
top: 0;
left: 0;
}
.borderTransition::after {
bottom: 0;
right: 0;
}
.borderTransition:hover::before,
.borderTransition:hover::after {
width: 100%;
height: 100%;
}
.borderTransition:hover::before {
border-top-color: #42cbf4;
border-right-color: #42cbf4;
/*transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;*/
transition: width 0.5s ease-out, height 0.5s ease-out 0.5s;
}
.borderTransition:hover::after {
border-bottom-color: #42cbf4;
border-left-color: #42cbf4;
transition: border-color 0s ease-out 1s, width 0.5s ease-out 1s, height 0.5s ease-out 1.5s;
}
@keyframes topRight {
0% {
left: 0%;
top: 0%;
width: 0%;
height: 0%;
}
25% {
left: 0%;
top: 0%;
width: 100%;
height: 0%;
}
50% {
right: 0%;
top: 0%;
width: 100%;
height: 100%;
}
75% {
right: 0%;
bottom: 0%;
width: 0%;
height: 100%;
}
100% {
right: 0%;
bottom: 0%;
width: 0%;
height: 0%;
}
}
@keyframes bottomLeft {
0% {
right: 0%;
bottom: 0%;
width: 0%;
height: 0%;
}
25% {
right: 0%;
bottom: 0%;
width: 100%;
height: 0%;
}
50% {
right: 0%;
bottom: 0%;
width: 100%;
height: 100%;
}
75% {
right:...