• 技术文章 >web前端 >前端问答

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

    青灯夜游青灯夜游2021-11-09 10:56:09原创427

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

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

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

    其中::link和:visited只能适用于设置超链接a,: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超链接伪类的作用是什么的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:css 超链接 伪类
    上一篇:javascript变量名称不能是保留字吗 下一篇:css作用和html的区别是什么
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【腾讯云】年中优惠,「专享618元」优惠券!• 纯CSS创建各类进度条的 N 种方式(总结分享)• 分享一个有趣的CSS3伪元素::marker,它使列表序号更生动• 10个值得收藏的CSS可视化工具(分享)• php无法加载js css怎么办• 12个值得收藏的 CSS 技巧!!
    1/1

    PHP中文网