4种css超链接伪类的作用是什么

2021-11-10,,

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

/2021/11/526a2f72.jpg

本教程操作环境: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);
}

alt="" height="182" /2021/11/8b8028b7.png" width="468

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

伪元素

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

::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: "☚";
}

alt="" height="467" /2021/11/687c054a.png" width="846

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

以上就是4种css超链接伪类的作用是什么的详细内容,更多请关注北冥有鱼其它相关文章!

本文转载自【PHP中文网】,希望能给您带来帮助,苟日新、日日新、又日新,生命不息,学习不止。

《4种css超链接伪类的作用是什么.doc》

下载本文的Word格式文档,以方便收藏与打印。