web----伪类和伪元素

伪类

a标签有四种伪类,建议按顺序书写 

 link  visited  hover  active 

<style>

        div{

            /* 常态 */

            width: 100px;

            height: 100px;

            background-color: gold;

        }

        div:hover{

            background-color: tomato;

        }

        a:link{

            /* 链接前 */

            color: tomato;

        }

        a:visited{

            /* 链接后 */

            color: skyblue;

        }

        a:hover{

            color:gold;  

        }

        a:active{

            color: pink;

        }

        input{

            outline:0 ;

        }

        input:focus{

            /* 获取焦点 */

            border: 2px solid orange;

        }

        ul li:first-child{

            /* 只能是第一个li,li是第一个子级元素 */

            color: red;

        }

        ul li:first-of-type{

            /* 第一个li类型的标签,li不用是第一个子元素 */

            color: skyblue;

        }

        ul li:last-child{

            /* 最后一个子级 */

            color: greenyellow;

        }

        ul li:last-of-type{

            /* 特定的最后一个子级 */

            color: blue;

        }  

         li:nth-child(2){

            /* 第n个子元素 */

             color: purple;

         }

        li:nth-of-type(2n){

            /* 指定类型的第n个子元素【推荐】 */

            color: hotpink;

        }

        li:nth-last-child(3){

            /* 倒数第n个子元素 */

            color: yellow;

        }

        li:nth-last-of-type(2n+1){

            /* 指定类型的倒数第n个子元素 */

            color: yellow;

        }

    </style>

伪元素

 <style>

        p{

            color: skyblue;

        }

        p::before{

            /* 元素前面的内容 */

            content: "大家好,我是";

            color: orange;

        }

        p::after{

            /* 元素后面的内容 */

            content: "欢迎大家学习C1";

            color: tomato;

        }

        div{

            width: 200px;

        }

        div::first-line{

            /*文本的第一行样式 */

            color: tomato;

        }

        div::first-letter{

            /* 文本的首字母,只用于块元素 */

            font-size: 40px

        }

        input::placeholder{

            /* 只用于表单的提示文本*/

            color: pink;

        }

    </style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值