How Can I Customize Text Underline Length and Position with CSS Gradients?

DDD
Release: 2024-11-07 11:19:03
Original
960 people have browsed it

How Can I Customize Text Underline Length and Position with CSS Gradients?

Customizing Text Underline Length and Position

To achieve customizable text underlines, CSS gradients offer a versatile solution. By tweaking parameters like background-size, background-position, and padding, you can effortlessly adjust both the length and position of the underline.

Adjusting Length:

Control the underline's length through the background-size property. Specify a percentage or fixed pixel value (e.g., 80% 2px) to scale the line's length.

Altering Position:

Manipulate the underline's position using background-position. By altering the horizontal and vertical coordinates, you can reposition the line relative to the text (e.g., bottom center for a central location).

Example:

.underline {
  background-image: linear-gradient(#5fca66 0 0);
  background-position: bottom center;
  background-size: 80% 2px;
  background-repeat: no-repeat;
  padding-bottom: 4px; /* controls position */
}
Copy after login

Additional Customizations:

In addition to length and position, you can enhance your underlines with various other properties:

  • small - Shortens the length significantly
  • left - Aligns the line to the left edge
  • center-close - Centers the line close to the text
  • right - Aligns the line to the right edge
  • close - Moves the line up close to the text
  • big - Increases the length and thickness
  • far - Adds a gap between the line and the text

The above is the detailed content of How Can I Customize Text Underline Length and Position with CSS Gradients?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!