css 中的伪类

CSS 伪类 (Pseudo-classes)

伪类包括选择器伪类、锚类伪类、内容伪类

    选择器      伪类               属性
    selector : pseudo-class {property: value}
---------------------------------------------------
    选择器     类      伪类               属性
    selector.class : pseudo-class {property: value}
  • 选择器伪类(:first-child、:nth-child(n)、:last-child)
  span:first-child{
    color:red;
  }
  li:nth-child(2n){
    font-size:22px;;
  }
  • 锚类伪类(:link、:visited、:hover 、:active)
  a:link {color: red}		//未访问的效果
  a:visited {color: green}	//已访问的效果
  a:hover {color: pink}	// 鼠标移动上的效果 
  a:active {color: blue}	// 选定的效果
  • 内容伪类(:after 、 :before)
  css
     p:after{
        content: '你是真的6';
        background: transparent;
     }
  html
     <p>--我很6--</p>

效果图:

在这里插入图片描述

css
	   .triangle{
            width:100px;
            height:20px;
            border:2px solid gray;
            position:relative;
        }
        .triangle:before{
            content:"";
            width:0;
            height:0;
            position:absolute;
            left:50%;
            margin-left: -12px;
            top:-12px;
            /*border-top:solid 12px red;*/
            border-left:solid 10px transparent;
            border-bottom:solid 10px gray;
            border-right:solid 10px transparent;
        }
        .triangle:after{
            content:"";
            width:0;
            height:0;
            position:absolute;
            left:50%;
            margin-left: -12px;
            top:-12px;
            /*border-top:solid 12px blue;*/
            border-bottom:solid 10px gray;
            border-left:solid 10px transparent;
            border-right:solid 10px transparent;
        }

html
      <div class="triangle"></div>

效果图:
在这里插入图片描述

再来个炫酷些的:

css
      .demo1{
            position: relative;
            text-decoration: none;
            font-size: 20px;
            color: #333;
        }
        .demo1:before{
            content: "";
            position: absolute;
            left: 50%;
            bottom: -2px;
            width: 0;
            height: 2px;
            background: #4285f4;
            transition: all .3s;
        }
        .demo1:hover:before{
            width: 100%;
            left: 0;
            right: 0;
        }


        .demo2{
            position: relative;
            text-decoration: none;
            font-size: 20px;
            color: #333;
        }
        .demo2:before{
            content: "";
            position: absolute;
            left: 0;
            bottom: -2px;
            height: 2px;
            width: 100%;
            background: #4285f4;
            transform: scale(0);
            transition: all 0.3s;
        }
        .demo2:hover:before{
            transform: scale(1);
        }
html 

    <a href="javascript:void(0);" class="demo1">这就是我想要的效果</a>
    <br>
    <br>
    <a href="javascript:void(0);" class="demo2">这也是我想要的效果</a>

来看看效果图:
在这里插入图片描述

  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值