<h1>CSS3 Button & Text-link<br>Hover Animations</h1>
<div class="container">
<p class="ttl_button">Button Hover<p/>
<div class="button-container">
<a href="#" class="button button-1">hover me!</a>
<a href="#" class="button button-2">hover me!</a>
<a href="#" class="button button-3"><span>hover me!</span></a>
<a href="#" class="button button-4">hover me!</a>
</div>
<p class="ttl_textlink">Text Link Hover<p/>
<div class="textlink-container">
<a href="#" class="textlink textlink-1">hover me!</a>
<br>
<a href="#" class="textlink textlink-2">hover me!</a>
<br>
<a href="#" class="textlink textlink-3">hover me!</a>
<br>
<a href="#" class="textlink textlink-4">hover me!</a>
<br>
<a href="#" class="textlink textlink-5">hover me!</a>
<br>
<a href="#" class="textlink textlink-6">hover me!</a>
</div>
</div>
body {
background-color: #333;
font-family: sans-serif;
padding: 30px;
}
h1 {
font-size: 50px;
line-height: 1.2;
text-align: center;
font-weight: bold;
padding: 20px 0;
color: #bff2fc;
}
p{
color: #d7f0f4;
text-align: center;
}
.ttl_textlink {
margin-top: 80px;
}
.container {
margin: 40px;
.button-container {
display: flex;
margin: 20px auto;
padding: 40px 20px;
background-color: #fff;
justify-content: space-between;
align-items: center;
}
.textlink-container {
display: flex;
margin: 20px auto;
padding: 40px 20px;
background-color: #fff;
justify-content: space-between;
align-items: center;
}
}
.button {
height: 50px;
width: 150px;
display: grid;
place-items: center;
color: #fff;
text-decoration: none;
background-color: #0FBEFF;
position: relative;
transition: all 0.6s ease;
border: 1px solid #0FBEFF;
}
// button-1
.button-1 {
&:hover {
opacity: 0.7;
}
}
// button-2
.button-2{
&:hover {
color: #0FBEFF;
background-color: #fff;
}
}
// button-3
.button-3 {
overflow: hidden;
position: relative;
color: #fff;
&::before {
content: "";
height: 50px;
width: 150px;
display: block;
position: absolute;
transform: translateX(-100%);
background-color: #fff;
transition: all 0.3s ease;
}
span {
position: relative;
z-index: 1;
}
&:hover {
&::before {
transform: translateX(0);
}
span {
color: #0FBEFF;
}
}
}
// button-4
@keyframes animate {
0% {
width: 0;
height: 0;
border-top-color: #0FBEFF;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: transparent;
}
50% {
width: 100%;
height: 0;
border-top-color: #0FBEFF;
border-right-color: #0FBEFF;
border-bottom-color: transparent;
border-left-color: transparent;
}
100% {
width: 100%;
height: 100%;
border-top-color: #0FBEFF;
border-right-color: #0FBEFF;
border-bottom-color: transparent;
border-left-color: transparent;
}
}
@keyframes animates {
0% {
width: 0;
height: 0;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: #0FBEFF;
}
50% {
width: 0;
height: 100%;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: #0FBEFF;
border-left-color: #0FBEFF;
}
100% {
width: 100%;
height: 100%;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: #0FBEFF;
border-left-color: #0FBEFF;
}
}
.button-4 {
&::before {
content: "";
position: absolute;
top: -1px;
left: -1px;
width: 0;
height: 0;
background: transparent;
border: 1px solid transparent;
}
&::after {
content: "";
position: absolute;
top: -1px;
left: -1px;
width: 0;
height: 0;
background: transparent;
border: 1px solid transparent;
}
&:hover {
color: #0FBEFF;
background-color: #fff;
border-color: transparent;
&::before {
animation: animate 0.4s linear forwards;
animation-delay: 0.3s;
}
&::after {
animation: animates 0.4s linear forwards;
animation-delay: 0.3s;
}
}
}
.textlink {
color: black;
text-decoration: none;
transition: all .3s ease;
display: inline-block;
}
// textlink-1
.textlink-1 {
&:hover {
color: #0FBEFF;
}
}
// textlink-2
.textlink-2 {
padding-bottom: 2px;
border-bottom: 1px solid transparent;
&:hover {
color: #0FBEFF;
border-bottom: 1px solid #0FBEFF;
}
}
// textlink-3
@keyframes textlink3 {
0% {
transform: translateX(-100%)
}
50% {
transform: translateX(0)
}
100% {
transform: translateX(100%)
}
}
.textlink-3 {
padding-bottom: 2px;
position: relative;
overflow: hidden;
&::before {
content: "";
position: absolute;
display: block;
width: 100%;
height: 1px;
background-color: #000;
bottom: 0;
transform: translateX(-100%);
}
&:hover {
&::before {
animation: textlink3 1s ease;
}
}
}
// textlink-4
@keyframes textlink4 {
0% {
transform: translateX(0)
}
49% {
transform: translateX(100%)
}
50% {
transform: translateX(-100%)
}
100% {
transform: translateX(0)
}
}
.textlink-4 {
padding-bottom: 2px;
position: relative;
overflow: hidden;
&::before {
content: "";
position: absolute;
display: block;
width: 100%;
height: 1px;
background-color: #000;
bottom: 0;
}
&:hover {
&::before {
animation: textlink4 1s ease;
}
}
}
// textlink-5
.textlink-5 {
padding-bottom: 2px;
position: relative;
overflow: hidden;
padding: 5px 0;
&::before {
content: "";
position: absolute;
display: block;
width: 100%;
height: 1px;
background-color: #000;
bottom: 0;
transition: all .3s ease;
transform: translateX(100%);
}
&::after {
content: "";
position: absolute;
display: block;
width: 100%;
height: 1px;
background-color: #000;
top: 0;
transition: all .3s ease;
transform: translateX(-100%);
}
&:hover {
&::before,
&::after {
transform: translateX(0);
}
}
}
// textlink-6
.textlink-6 {
padding-bottom: 2px;
position: relative;
overflow: hidden;
&::before {
content: "";
position: absolute;
display: block;
height: 1px;
background-color: #000;
bottom: 0;
transition: all .3s ease;
width: 0;
left: 50%;
}
&:hover {
&::before {
left: 0;
width: 100%;
}
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.