4种css超链接伪类的作用:1、“:link”,定义正常链接的样式;2、“:visited”,定义已访问过链接的样式;3、“:hover”,定义鼠标悬浮在链接上时的样式;4、“active”,定义鼠标点击链接时的样式。

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

因为我们要定义链接样式,所以其中必不可少的就是超级链接中的锚标签–a,锚标签和伪类链接起来书写的方法就是定义链接样式的基础方法,它们的写法如下:

  • a:link,定义正常链接的样式;

  • a:visited,定义已访问过链接的样式;

  • a:hover,定义鼠标悬浮在链接上时的样式;

  • a:active,定义鼠标点击链接时的样式。

其中::link和:visited只能适用于设置超链接a,:hover和:active则可适用所有元素

  • :hover 用来表示鼠标移入的状态

  • :active 用来表示鼠标点击

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>超链接的伪类</title>
    <link rel="stylesheet" href="../css/a.css">
</head>
<body>
     <a href="https://www.12345.com/" target="__blank">没访问过的链接</a>
     <br>
     <a href="https://www.csdn.net/" target="__blank">访问过的链接</a>
</body>
</html>
/* 没访问过的链接状态 */
a:link{
    font-size: 20px;
    color: hotpink;
}
/* 访问过的链接状态 */
a:visited{
    color: green;
}
/* 鼠标移入链接时的状态 */
a:hover{
    color: rgb(0, 217, 255);
}
/* 鼠标点击链接时的状态 */
a:active{
    color: rgb(255, 0, 0);
}

注意:只要曾经搜索过都算访问过的,除非清除历史浏览缓存数据。

伪元素

伪元素,页面中一些特殊的并不真实存在的元素,伪元素表示一些特殊的位置。伪元素使用 :: 开头

::first-letter 表示第一个字母
::first-line 表示第一行
::selection 表示选中的内容
::before 元素的开始
::after 元素的最后

注意:

1、因为设置::before和::after没有任何效果,所以::before和::after必须结合content属性来使用。 2、content内添加的内容鼠标无法选中。
3、html中的q标签表示短引用,有增加双引号效果,原理是运用了::before和::after属性,content中加上了双引号,所以q标签的双引号也无法选中。

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>伪元素</title>
    <link rel="stylesheet" href="../css/pseudo_element.css">
</head>
<body>
    <h3>WHERE THERE IS A WILL, THERE IS A WAY</h3>
     <p>The secret of success (The key to success) is not so much money as a strong will. A great man is one who has a strong will and an indomitable spirit. In other words, if a man does not have a strong will to win (get) the final victory, he will never succeed in his life. He is no more than a failure.It is quite obvious that there is no difficult thing (nothing difficult) in the world. if you make up your mind to do it, you will certainly accomplish your end. That stands to reason.</p>
</body>
</html>
/* 第一个字母设置像素为50px */
::first-letter{
    font-size: 50px;
}
/* 第一行设置绿色 */
::first-line{
    color: green;
}
/* 鼠标选中的字体背景设置为橙色 */
::selection{
    background-color: sandybrown;
}
/* 元素p内容开始之前添加符号 ,结尾添加符号,注意该符号鼠标无法被选中*/
p::before{
    content: "";
}
p::after{
    content: "";
}

(学习视频分享:css视频教程)

以上就是4种css超链接伪类的作用是什么的详细内容,更多请关注美工之家9502669.com其它相关文章!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。