CSS3选择器代码笔记

CSS3选择器代码笔记

css导入方式

<link rel="stylesheet" href="">

选择器

选择页面上某一/某一类的元素

基本选择器

  1. 类选择器

    .class1{
        font-size: 20px;
    }
    
  2. id选择器

    #class1{
        font-size: 20px;
    }
    
  3. 标签选择器:会选择页面上的所以的标签

h1{
   
}
  1. 层次选择器

    • 后代选择器

      ul li{
       color: #B5FFFC;
      }
      
    • 子选择器

      div>p{
      color: #B5FFFC;
      }
      
    • 相邻兄弟选择器

      .name+p{
       <!--相邻及向下-->
      color: #B5FFFC;
      }
      
    • 通用兄弟选择器

    .name~p{
     <!--相邻兄弟-->
    color: #B5FFFC;
    }
    
  2. 结构伪类选择器

    ul li:first-child{
        font-size: 20px;
    }
     ul li:last-child{
                    font-size: 20px;
                }
                
                
    /*选中p1:定位到父元素,选择当前的第一个元素,选择当元素的父级元素,选中父级元素的第一个, 并且是当前元素才生效!
    */
    p:nth-child(1){
                    font-size: 20px;
                }
                
                
      p:nth-of-type(1){
                   font-size: 20px;
               }
       a:hover{
       font-size: 20px;
       }
       
    
  3. 属性选择器可以使用正则表达式

    a[id]{
    font-size: 20px;
    }
    a[id=first]{
    font-size: 20px;
    }
    a[class *= link]{
    font-size: 20px;
    }
    /*以link开头
    */
    a[href ^= link]{
    font-size: 20px;
    }
    /*以link结尾
    */
    a[href  $= link]{
    font-size: 20px;
    }
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值