a標籤偽類的使用
阿新 • • 發佈:2018-11-15
a標籤的偽類
偽類的作用
- :link => 向未被訪問的連結新增樣式。
- :visited => :visited 向已被訪問的連結新增樣式。
- :hover => :hover 當滑鼠懸浮在元素上方時,向元素新增樣式。
- :active => :active 向被啟用的元素新增樣式。即滑鼠按下時的樣式。
程式碼舉例
HTML檔案
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>a標籤偽類的使用</title>
<link rel="stylesheet" type="text/css" href="css/a.css"/>
</head>
<body>
<div class="container">
<a target="_blank" href="https://blog.csdn.net/" class ="link">:link 向未被訪問的連結新增樣式。</a>
<a target="_blank" href="https://www.imooc.com/" class="visited">:visited 向已被訪問的連結新增樣式。</a>
<a target="_blank" href="https://www.baidu.com/" class="hover">:hover 當滑鼠懸浮在元素上方時,向元素新增樣式。</a>
<a target="_blank" href="https://www.jianshu.com/" class="active">:active 向被啟用的元素新增樣式。即滑鼠按下時的樣式。</a>
</div>
</body>
</html>
CSS檔案
* {
margin: 0;
padding: 0;
}
.container {
padding: 20px;
margin: auto;
width: 900px;
}
a {
width: 800px;
height: 120px;
border: 1px dashed #000000;
text-decoration: none;
font-size: 30px;
padding: 10px 20px;
text-align: center;
display: block;
border-radius: 15px;
line-height: 120px;
margin-bottom: 30px;
font-weight: bold;
}
a:nth-last-child {
margin-top: 30px;
}
.link:link {
background-color: blueviolet;
}
.active:active {
background-color: green;
}
.hover:hover {
background-color: yellow;
}
.visited:visited {
background-color: peru !important;
color: #000000;
}
溫馨提示
- a:hover 放置在 a:link 與 a:visited 之後;
- a:active 放置在 a:hover 之後;