Home > Article > Web Front-end > 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 */ }
Additional Customizations:
In addition to length and position, you can enhance your underlines with various other properties:
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!