首頁 > web前端 > css教學 > 如何使用 :after 和可變寬度文字刪除附加 URL 中的底線?

如何使用 :after 和可變寬度文字刪除附加 URL 中的底線?

Susan Sarandon
發布: 2024-11-15 00:45:02
原創
514 人瀏覽過

How to Remove the Underline from Appended URLs with :after and Variable Width Text?

Addressing Text Decoration and the :after Pseudo-Element

In an earlier inquiry, the issue of using the :after pseudo-class to append URLs to links in a printed style sheet was raised. However, the provided answers proved insufficient.

The primary concern was the inability to remove the default underline styling from the appended URL, despite explicitly setting 'text-decoration: none;'. This resulted in an unappealing underline extending beneath the URL in browsers such as Firefox and Chrome.

A Solution for Variable Width Text

The previously suggested solutions employed techniques like padding and background images to circumvent the problematic text decoration property. However, these methods are not applicable when the appended content is variable width text.

To resolve this, modify the display property of the :after pseudo-element to 'inline-block'. This allows the 'text-decoration: none;' declaration to take effect, as demonstrated in the following code:

a:after {
    content: " <" attr(href) ">";
    text-decoration: none;
    color: #000000;
    display: inline-block;
}
登入後複製

This adjusted CSS ensures that the appended URL displays without any underline, regardless of its width. By applying this workaround, you can effectively append variable width text to links and specify its desired color, thereby addressing the initial concern and providing a more refined printed rendering of URLs.

以上是如何使用 :after 和可變寬度文字刪除附加 URL 中的底線?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板