How Can I Change the Color of an Underline in CSS?

Patricia Arquette
Release: 2024-11-04 16:28:02
Original
430 people have browsed it

How Can I Change the Color of an Underline in CSS?

CSS text-decoration underline color

In web development, there are scenarios where you may desire to stylize the underline of text. This article addresses the challenge of changing the color of the underline below a line of text, creating a distinct visual effect.

Solution 1: text-decoration-color (Modern Browsers)

For modern browsers that support the text-decoration-color property, simply apply the following CSS rule:

text-decoration-color: green;
Copy after login

This method allows for direct specification of the underline color.

Solution 2: border-bottom (Older Browsers)

If the text-decoration-color property is not supported by an older browser, an alternative approach is to utilize the border-bottom property:

a:link {
  color: red;
  text-decoration: none;
  border-bottom: 1px solid blue;
}
a:hover {
 border-bottom-color: green;
}
Copy after login

This approach adds a colored border to the bottom of the text, effectively mimicking the appearance of an underline.

The above is the detailed content of How Can I Change the Color of an Underline in CSS?. 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