html中的各类选择器

基础选择器

标签选择器:一次性把页面所有一类的标签选择出来

<style>
  p{
       color:aqua;
    }
</style>

<body>
  <p>xxxx</p>
</body>

类选择器:选择同一类,class为全局属性

<style>
  .box{
       color:aqua;
    }
</style>

<body>
  <div class="box">xxxxx</div>
</body>

id选择器:身份证号码,每个网页里不能重复

<style>
  #box{
       color:aqua;
    }
</style>

<body>
  <div id="box">xxxx</div>
</body>

通配符选择器:选中所有标签

<style>
  *{
       color:aqua;
    }
</style>

<body>
  <p>xxxx</p>
  <div>scsa</div>
</body>

包含选择器

子代选择器:选择亲儿子

<style>
  .a>li{
       color:aqua;
    }
</style>

<body>
  <ul class="a">
      <li>1</li>
      <li>2</li>
      <ul>
            <li>3</li>
            <li>4</li>
      </ul>
 </ul>
</body>
仅显示12

后代选择器

选择全部后代

<style>
  .a>li{
       color:aqua;
    }
</style>

<body>
  <ul class="a">
      <li>1</li>
      <li>2</li>
      <ul>
            <li>3</li>
            <li>4</li>
      </ul>
 </ul>
</body>
1234均会显示

复合选择器

逗号选择器:把多个元素选择出来相叠加

<style>
  span,
  div,
  p {
       color:aqua;
    }
</style>

<body>
   <div>xxxx</div>
   <p>xxxxs</p>
   <span>xxxxss</span>
</body>

属性选择器

<style>
        input {
            background-color: pink;
        }
 
        input[type="password"] {
            background-color: aquamarine;
        }
 
        div[id] {
            width: 300px;
            height: 300px;
            background-color: blue;
        }
 
        /* type^="te"以te开头 */
        input[type^="te"] {
            background-color: red;
        }
        /* type$="l"表示以l结尾 */
        input[type$="l"] {
            background-color: green;
        }
 
        /* type*="e"    type值里边包含e */
        input[type*="e"] {
            background-color: chartreuse;
        }
    </style>
</head>
 
<body>
    <input type="text"><br />
    <input type="password"><br />
    <input type="search"><br />
    <input type="url"><br />
    <input type="number"><br />
    <div id="aquamarine">1</div>
    <div>2</div>
</body>

伪类选择器

hover

鼠标经过时

visited鼠标访问过后
active鼠标按下弹起
<style>
    a:hover{
       color:aqua;
           }
</style>

<body>
    <a href="#">去百度</a>
</body>

结构伪类选择器

 nth-child(n)与nth-of-child(n)有不同的用法

nth-child(n)  先排序后查找目标元素

nth-of-child  先查找目标元素后排序

伪类元素选择器

<style>
/* 在所选结构前面都加上 >   */
        ul li::before {
            content: ">";
        }

        ul li::after {
            content: url();
        }

        /* input::placeholder  表单提示词 */
        input::placeholder {
            color: rgb(62, 226, 56);
        }


        /* ::selection 选中时 */
        ul li:nth-child(4)::selection {
            color: pink;
        }
    </style>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值