<div class="text-center">
<h1>Arrow @keyframes Animation</h1>
<hr>
<br/>
Using checkbox as the basis of the arrow state.
</div>
<br/><br/><br/><br/>
<div class="text-center">
<input type="checkbox" id="animation1">
<label for="animation1">
<div class="arrow"></div>
</label>
<input type="checkbox" id="animation2">
<label for="animation2">
<div class="arrow"></div>
</label>
<input type="checkbox" id="animation3">
<label for="animation3">
<div class="arrow"></div>
</label>
</div>
.arrow {
background: #fff;
height: 3px;
width: 30px;
margin: 0 auto;
position: relative;
cursor: pointer;
&:before,
&:after {
content: "";
background: #fff;
position: absolute;
height: 3px;
width: 15px;
}
&:before {
right: -3px;
bottom: -4px;
transform: rotate(-45deg);
}
&:after {
right: -3px;
top: -4px;
transform: rotate(45deg);
}
}
// Animation 1
#animation1 {
& + label > .arrow {
&:before {
animation: animation-1-before-reverse 1s ease 0s 1 alternate both;
}
&:after {
animation: animation-1-after-reverse 1s ease 0s 1 alternate both;
}
}
&:checked {
& + label > .arrow {
&:before {
animation: animation-1-before 1s ease 0s 1 alternate both;
}
&:after {
animation: animation-1-after 1s ease 0s 1 alternate both;
}
}
}
}
@keyframes animation-1-after {
0% {
right: -3px;
top: -4px;
transform: rotate(45deg);
}
50% {
width: 3px;
border-radius: 50%;
top: -20px;
left: 15px;
}
100% {
left: -3px;
bottom: -4px;
transform: rotate(135deg);
height: 3px;
width: 15px;
background: #fff;
}
}
@keyframes animation-1-before {
0% {
right: -3px;
bottom: -4px;
transform: rotate(-45deg);
}
50% {
width: 3px;
border-radius: 50%;
bottom: -20px;
left: 15px;
}
100% {
left: -3px;
bottom: -4px;
transform: rotate(-135deg);
height: 3px;
width: 15px;
background: #fff;
}
}
@keyframes animation-1-after-reverse {
0% {
left: -3px;
bottom: -4px;
transform: rotate(135deg);
height: 3px;
width: 15px;
background: #fff;
}
50% {
width: 3px;
border-radius: 50%;
top: -20px;
left: 15px;
}
100% {
right: -3px;
top: -4px;
transform: rotate(45deg);
}
}
@keyframes animation-1-before-reverse {
0% {
left: -3px;
bottom: -4px;
transform: rotate(-135deg);
height: 3px;
width: 15px;
background: #fff;
}
50% {
width: 3px;
border-radius: 50%;
bottom: -20px;
left: 15px;
}
100% {
right: -3px;
bottom: -4px;
transform: rotate(-45deg);
}
}
// Animation 1
#animation2 {
& + label > .arrow {
&:before {
animation: animation-2-before-reverse 1s ease 0s 1 alternate both;
}
&:after {
animation: animation-2-after-reverse 1s ease 0s 1 alternate both;
}
}
&:checked {
& + label > .arrow {
&:before {
animation: animation-2-before 1s ease 0s 1 alternate both;
}
&:after {
animation: animation-2-after 1s ease 0s 1 alternate both;
}
}
}
}
@keyframes animation-2-after {
0% {
right: -3px;
top: -4px;
transform: rotate(45deg);
background: blue;
}
50% {
width: 3px;
border-radius: 50%;
top: 20px;
left: 15px;
}
100% {
left: -3px;
bottom: -4px;
transform: rotate(135deg);
height: 3px;
width: 15px;
background: #fff;
}
}
@keyframes animation-2-before {
0% {
right: -3px;
bottom: -4px;
transform: rotate(-45deg);
background: red;
}
50% {
width: 3px;
border-radius: 50%;
bottom: 20px;
left: 15px;
}
100% {
left: -3px;
bottom: -4px;
transform: rotate(-135deg);
height: 3px;
width: 15px;
background: #fff;
}
}
@keyframes animation-2-after-reverse {
0% {
left: -3px;
bottom: -4px;
transform: rotate(135deg);
height: 3px;
width: 15px;
background: #fff;
}
50% {
width: 3px;
border-radius: 50%;
top: 20px;
left: 15px;
background: red;
}
100% {
right: -3px;
top: -4px;
transform: rotate(45deg);
background: #fff;
}
}
@keyframes animation-2-before-reverse {
0% {
left: -3px;
bottom: -4px;
transform: rotate(-135deg);
height: 3px;
width: 15px;
background: #fff;
}
50% {
width: 3px;
border-radius: 50%;
bottom: 20px;
left: 15px;
background: blue;
}
100% {
right: -3px;
bottom: -4px;
transform: rotate(-45deg);
background: #fff;
}
}
#animation3 {
& + label > .arrow {
&:before {
animation: animation-3-before-reverse 1s ease 0s 1 alternate both;
}
&:after {
animation: animation-3-after-reverse 1s ease 0s 1 alternate both;
}
}
&:checked {
& + label > .arrow {
&:before {
animation: animation-3-before 1s ease 0s 1 alternate both;
}
&:after {
animation: animation-3-after 1s ease 0s 1 alternate both;
}
}
}
}
@keyframes animation-3-after {
0% {
right: -3px;
top: -4px;
transform: rotate(45deg);
background: blue;
}
25% {
width: 3px;
border-radius: 50%;
top: 20px;
left: 15px;
}
75% {
width: 3px;
border-radius: 50%;
top: -20px;
left: 15px;
}
100% {
left: -3px;
bottom: -4px;
transform: rotate(135deg);
height: 3px;
width: 15px;
background: #fff;
}
}
@keyframes animation-3-before {
0% {
right: -3px;
top: -4px;
transform: rotate(45deg);
background: red;
}
25% {
width: 3px;
border-radius: 50%;
top: -20px;
left: 15px;
}
75% {
width: 3px;
border-radius: 50%;
top: 20px;
left: 15px;
}
100% {
left: -3px;
bottom: -4px;
transform: rotate(-135deg);
height: 3px;
width: 15px;
background: #fff;
}
}
@keyframes animation-3-after-reverse {
0% {
left: -3px;
bottom: -4px;
transform: rotate(135deg);
height: 3px;
width: 15px;
background: #fff;
}
50% {
width: 3px;
border-radius: 50%;
top: -20px;
left: 15px;
}
100% {
right: -3px;
top: -4px;
transform: rotate(45deg);
}
}
@keyframes animation-3-before-reverse {
0% {
left: -3px;
bottom: -4px;
transform: rotate(-135deg);
height: 3px;
width: 15px;
background: #fff;
}
50% {
width: 3px;
border-radius: 50%;
bottom: -20px;
left: 15px;
}
100% {
right: -3px;
bottom: -4px;
transform: rotate(-45deg);
}
}
// General
body {
background: #000;
color: #fff;
}
.text-center {
text-align: center;
}
hr {
border: none;
height: 1px;
width: 20%;
background: #fff;
}
input {
display: none;
}
label {
margin-bottom: 100px;
display: block;
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.