如何僅使用 CSS 顯示連結?
要停用任何網站的連結,我們使用 CSS 的屬性,例如將 pointer-event 設定為 none,然後游標可以設定為預設值,這將停用活動連結,使用者無法訪問連結。有時需要停用連結以對網站進行一些更新或安全措施。政府或組織最適合此示例,每當他們需要對網站後端進行任何更新時,他們只需停用連結。
在本文中,我們將展示如何僅使用 CSS 顯示連結。
語法
<a href="link_of_any_website" class="class_name"></a>
這是一個錨標記,用於表示站點的連結。class_name 是一個屬性,用於定義特定元素的 CSS 屬性。
使用的屬性
示例中使用的屬性如下:
color - 定義文字的顏色。
opacity - 定義 HTML 中文字或影像的透明度級別。
text-decoration - 定義新增到文字的裝飾,例如下劃線、上劃線、刪除線、下劃線上劃線和無。
pointer-event - 定義元素如何響應事件。例如 - 連結是否處於活動狀態或非活動狀態。
cursor - 定義滑鼠在指向任何連結時移動。
font-weight - 定義文字粗細。
示例
在此示例中,我們使用了兩個名為 active 和 not-active 的類。非活動類設定名為 pointer-event 的屬性,這將停用錨元素中使用的連結,但在活動類中,連結已啟用。
<!DOCTYPE html> <html> <title>Tutorialspoint</title> <head> <style> h1{ color: darkgreen; } .not-active{ opacity: 0.6; text-decoration: none; pointer-events: none; cursor: default; color: blue; font-weight: bold; } .active{ opacity: 0.6; text-decoration: none; color: blue; font-weight: bold; } </style> </head> <body> <center> <h1>Tutorialspoint</h1> <h3 style="color: green">(www.tutorialspoint.com)</h3> <p>The Disable link: <a href="https://tutorialspoint.tw" class="not-active">Click Here</a> </p> <p>The Enable link: <a href="https://tutorialspoint.tw" class="active">Click Here</a> </p> </center> </body> </html>
結論
我們瞭解了透過使用 CSS 的一些屬性在 CSS 中停用和啟用連結之間的區別。要停用連結,我們已將名為 not-active 的類的一些屬性(如指標和文字裝飾)的值設定為 none。因此,僅使用 CSS 即可停用連結。
廣告