How to Create an Animated Expansion of Border Bottom on Hover?

Susan Sarandon
Release: 2024-11-16 08:48:03
Original
851 people have browsed it

How to Create an Animated Expansion of Border Bottom on Hover?

Hover Effect: Animated Expansion of Border Bottom

In this question, the goal is to create a hover effect that extends the bottom border of an element upon hovering. To achieve this effect, we can utilize the transform property and transition it from 0 to 1 on hover.

h1 {
  color: #666;
  display: inline-block;
  margin: 0;
  text-transform: uppercase;
}

h1:after {
  display: block;
  content: '';
  border-bottom: solid 3px #019fb6;
  transform: scaleX(0);
  transition: transform 250ms ease-in-out;
}

h1:hover:after {
  transform: scaleX(1);
}
Copy after login

This approach uses a pseudo-element to separate the border transition from the text, preserving the original HTML structure. The transform-origin property can be manipulated to expand the border from different directions, as illustrated below:

<h1>
Copy after login
h1.fromRight:after {
  transform-origin: 100% 50%;
}

h1.fromLeft:after {
  transform-origin: 0% 50%;
}
Copy after login

The above is the detailed content of How to Create an Animated Expansion of Border Bottom on Hover?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template