日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > CSS >内容正文

CSS

4、CSS 链接

發布時間:2025/3/20 CSS 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 4、CSS 链接 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我們能夠以不同的方法為鏈接設置樣式。

1、設置鏈接的樣式

能夠設置鏈接樣式的 CSS 屬性有很多種(例如 color, font-family, background 等等)。

鏈接的特殊性在于能夠根據它們所處的狀態來設置它們的樣式。

鏈接的四種狀態:

  • a:link - 普通的、未被訪問的鏈接
  • a:visited - 用戶已訪問的鏈接
  • a:hover - 鼠標指針位于鏈接的上方
  • a:active - 鏈接被點擊的時刻

實例

a:link {color:#FF0000;} /* 未被訪問的鏈接 */ a:visited {color:#00FF00;} /* 已被訪問的鏈接 */ a:hover {color:#FF00FF;} /* 鼠標指針移動到鏈接上 */ a:active {color:#0000FF;} /* 正在被點擊的鏈接 */

當為鏈接的不同狀態設置樣式時,請按照以下次序規則:

<!DOCTYPE html> <html> <head> <style> a:link {color:#FF0000;} /* 未被訪問的鏈接 */ a:visited {color:#00FF00;} /* 已被訪問的鏈接 */ a:hover {color:#FF00FF;} /* 鼠標指針移動到鏈接上 */ a:active {color:#0000FF;} /* 正在被點擊的鏈接 */ </style> </head><body> <p><b><a href="/index.html" target="_blank">這是一個鏈接</a></b></p> <p><b>注釋:</b>為了使定義生效,a:hover 必須位于 a:link 和 a:visited 之后!!</p> <p><b>注釋:</b>為了使定義生效,a:active 必須位于 a:hover 之后!!</p> </body> </html>

  • a:hover 必須位于 a:link 和 a:visited 之后
  • a:active 必須位于 a:hover 之后

2、常見的鏈接樣式

在上面的例子中,鏈接根據其狀態改變顏色。

讓我們看看其他幾種常見的設置鏈接樣式的方法:

  • 文本修飾

text-decoration 屬性大多用于去掉鏈接中的下劃線:

實例

a:link {text-decoration:none;} a:visited {text-decoration:none;} a:hover {text-decoration:underline;} a:active {text-decoration:underline;} <!DOCTYPE html> <html> <head> <style> a:link {text-decoration:none;} /* 未被訪問的鏈接 */ a:visited {text-decoration:none;} /* 已被訪問的鏈接 */ a:hover {text-decoration:underline;} /* 鼠標指針移動到鏈接上 */ a:active {text-decoration:underline;} /* 正在被點擊的鏈接 */ </style> </head><body> <p><b><a href="/index.html" target="_blank">這是一個鏈接</a></b></p> <p><b>注釋:</b>為了使定義生效,a:hover 必須位于 a:link 和 a:visited 之后!!</p> <p><b>注釋:</b>為了使定義生效,a:active 必須位于 a:hover 之后!!</p> </body> </html>

  • 背景色

background-color 屬性規定鏈接的背景色:

a:link {background-color:#B2FF99;} a:visited {background-color:#FFFF85;} a:hover {background-color:#FF704D;} a:active {background-color:#FF704D;}

實例

  • 向鏈接添加不同的樣式
  • <!DOCTYPE html> <html> <head> <style> a.one:link {color:#ff0000;} a.one:visited {color:#0000ff;} a.one:hover {color:#ffcc00;}a.two:link {color:#ff0000;} a.two:visited {color:#0000ff;} a.two:hover {font-size:150%;}a.three:link {color:#ff0000;} a.three:visited {color:#0000ff;} a.three:hover {background:#66ff66;}a.four:link {color:#ff0000;} a.four:visited {color:#0000ff;} a.four:hover {font-family:'微軟雅黑';}a.five:link {color:#ff0000;text-decoration:none;} a.five:visited {color:#0000ff;text-decoration:none;} a.five:hover {text-decoration:underline;} </style> </head><body> <p>請把鼠標指針移動到下面的鏈接上,看看它們的樣式變化。</p><p><b><a class="one" href="/index.html" target="_blank">這個鏈接改變顏色</a></b></p> <p><b><a class="two" href="/index.html" target="_blank">這個鏈接改變字體尺寸</a></b></p> <p><b><a class="three" href="/index.html" target="_blank">這個鏈接改變背景色</a></b></p> <p><b><a class="four" href="/index.html" target="_blank">這個鏈接改變字體</a></b></p> <p><b><a class="five" href="/index.html" target="_blank">這個鏈接改變文本的裝飾</a></b></p> </body></html>
  • 創建鏈接框
  • <!DOCTYPE html> <html> <head> <style> a:link,a:visited { display:block; font-weight:bold; font-size:14px; font-family:Verdana, Arial, Helvetica, sans-serif; color:#FFFFFF; background-color:#98bf21; width:120px; text-align:center; padding:4px; text-decoration:none; }a:hover,a:active { background-color:#7A991A; } </style> </head><body> <a href="/index.html" target="_blank">W3School</a> </body> </html>

    總結

    以上是生活随笔為你收集整理的4、CSS 链接的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。