I'm trying to apply linear-gradient
to border-bottom
on hover
to an <a>
but it didn't work 100% My aim is to make this with HTML and CSS only if possible.
Here is my code:
a {
font-size: 30px;
text-decoration: none;
color: #666;
cursor: pointer;
padding-right: 3%;
padding-bottom: 3%;
position: relative;
display: inline-block;
}
a:after {
content: '';
position: absolute;
left: -50%;
right: 0%;
border-top: 0;
border-left: 0;
border-right: 0;
border-image: -webkit-linear-gradient(left, #f0f0f0, #0a389b, #f0f0f0);
border-image: -moz-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0);
border-image: -ms-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0);
border-image: -o-linear-gradient(left, #f0f0f0, #8c8b8b, #f0f0f0);
transition: all 0.5s linear;
bottom: 0;
opacity: 0;
}
a:hover:after {
border-right: 25vh;
right: 0%;
opacity: 1;
}
<div>
<a href="#">First</a>
<a href="#">Second</a>
<a href="#">This is the third</a>
</div>
As you can see the border-bottom
is not in the center
and is not suitable for the width
of the <a>
width
.
You can use the same technique described here : Expand bottom border from center on hover with two box-shadows to create the fade out effect on the left and right edges :
a {
font-size: 30px;
text-decoration: none;
color: #666;
cursor: pointer;
padding-right: 3%;
padding-bottom: 3%;
position: relative;
display: inline-block;
}
a:after {
display:block;
content: '';
height:4px;
background:#019fb6;
transform: scaleX(0.0001);
transition: transform 250ms ease-in-out;
box-shadow: inset -40px 0px 30px -25px #fff, inset 40px 0px 30px -25px #fff;
}
a:hover:after {
transform: scaleX(1);
}
<div>
<a href="#">First</a>
<a href="#">Second</a>
<a href="#">This is the third</a>
</div>
Note : You need to insert vendor prefixes to maximize browser support (see canIuse).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With