首頁  >  文章  >  web前端  >  如何在保持文字顏色相同的情況下更改下劃線顏色?

如何在保持文字顏色相同的情況下更改下劃線顏色?

Susan Sarandon
Susan Sarandon原創
2024-11-14 21:03:02918瀏覽

How to Change Underline Color While Keeping Text Color the Same?

Changing Underline Color: Separating Text and Underline Hues

In order to maintain a red text color while changing the underline color to black, let's explore a solution leveraging a novel CSS3 property: text-decoration-color.

With this property, we can assign distinct colors to the text itself and the underline decoration, eliminating the need for additional wrapper elements. Here's an updated code snippet:

p {
  text-decoration: underline;
  -webkit-text-decoration-color: red; /* Safari still uses a vendor prefix */
  text-decoration-color: red;
}
<p>Black text with red underline in one element - no wrapper elements here!</p>

By leveraging the text-decoration-color property, we can achieve the desired effect of having black underlined text without sacrificing the red text color.

以上是如何在保持文字顏色相同的情況下更改下劃線顏色?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn