CSS(层叠样式表)用于描述HTML文档的外观和格式。超链接(<a>
标签)是网页中用于从一个页面链接到另一个页面的元素。通过CSS,可以自定义超链接在不同状态下的样式,包括鼠标悬停(:hover
)、访问过(:visited
)、激活(:active
)和链接(:link
)状态。
:link
:未访问过的链接。:visited
:访问过后的链接。:hover
:鼠标悬停在链接上时的样式。:active
:链接被点击时的样式。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Hyperlink Hover Style</title>
<style>
/* 默认链接样式 */
a:link {
color: blue;
text-decoration: none;
}
/* 访问过的链接样式 */
a:visited {
color: purple;
}
/* 鼠标悬停时的样式 */
a:hover {
color: red;
background-color: yellow;
}
/* 链接被点击时的样式 */
a:active {
color: green;
}
</style>
</head>
<body>
<a href="https://www.example.com">Visit Example</a>
</body>
</html>
原因:
解决方法:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Hyperlink Hover Style</title>
<style>
/* 默认链接样式 */
a:link {
color: blue;
text-decoration: none;
}
/* 访问过的链接样式 */
a:visited {
color: purple;
}
/* 鼠标悬停时的样式 */
a:hover {
color: red;
background-color: yellow;
}
/* 链接被点击时的样式 */
a:active {
color: green;
}
</style>
</head>
<body>
<a href="https://www.example.com">Visit Example</a>
</body>
</html>
通过以上步骤,可以确保CSS超链接鼠标样式正确应用并生效。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云