I'm trying to recreate the animation on description and review here. The underline animates from right to left when the link is unclicked the underline animates from left to right before it disappears.
a {
color:#00f;
text-decoration:none;
display:inline-block;
}
a:after {
width: 0;
display:block;
background:#00f;
height:3px;
transition: all .5s ease-in-out;
content:"";
}
a:hover {
color:#00f;
}
a:hover:after {
width:100%;
}
<a href="#">Click first</a>
<a href="#">Click second</a>
Use display: inline-block to make the underline span just the width of the text content. Use the :after pseudo-element with width: 100% and position: absolute to place it below the content. Use transform: scaleX(0) to initially hide the pseudo-element.
Let's say, “Underline my text.” And place the text at your desired position. As you want to animate your text, put it in the center. Now go to layers, select new, and select solid fill. Besides the color option on the pop-out screen, select the eyedropper button to match it with the color of your text and hit okay.
How to Underline a Title in CSS. To underline a title, you can use text-decoration: underline; but you can make it prettier if you use the border-bottom property. In the latter case, however, you need to add display: inline; so that the underline wouldn't be longer than the word itself.
Use position
on the pseudoelement. Add position: relative
to a
, and position: absolute
to :after
.
Position the pseudoelement using bottom
and right
. This means the line originates from the right side.
On hover/click, add the left
property. This makes the line span the full width. The width grows from 0
to 100%
from left to right.
When you 'unhover' or click again, left
is removed, and the line originates from the right again, so the width decreases in that direction.
$('a').on('click', function() {
$('a').not(this).removeClass('underline');
$(this).toggleClass('underline');
});
a {
color: #00f;
text-decoration: none;
display: inline-block;
position: relative;
}
a:after {
width: 0;
background: #00f;
height: 3px;
transition: all .5s ease-in-out;
content: "";
position: absolute;
bottom: -5px;
right: 0;
}
a.underline:after {
width: 100%;
left: 0;
}
a:hover:after {
width: 100%;
left: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#">Click first</a>
<a href="#">Click second</a>
Maybe you want a HTML/CSS only solution:
a {
color: #00f;
text-decoration: none;
display: inline-block;
}
a span:after {
width: 0;
display: block;
background: #00f;
height: 3px;
transition: all .5s ease-in-out;
content: "";
float: right;
}
a span:focus {
color: #00f;
}
label:hover {
cursor: pointer;
}
label input {
display: none;
}
label input:checked + span:after, label input + span:hover:after {
width: 100%;
float: left;
}
label input:checked + span {
color: #00f;
}
<a href="#">
<label>
<input type="radio" name="link" />
<span>
Click first
</span>
</label>
</a>
<a href="#">
<label>
<input type="radio" name="link" />
<span>
Click second
</span>
</label>
</a>
You can use the following. Just use a class to set style.
$('a').click(function(e){
$(this).siblings().removeClass('start');
$(this).toggleClass('start');
e.preventDefault();
})
a {
color:#00f;
text-decoration:none;
display:inline-block;
}
a:after {
width: 0;
display:block;
background:#00f;
height:3px;
transition: all .5s ease-in-out;
content:"";
float:right;
}
a:hover {
color:#00f;
}
a.start:after {
width: 100%;
}
a:hover:after {
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#">Click first</a>
<a href="#">Click second</a>
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