css常用选择器

目录

一、基础选择器

1.标签选择器

2.类选择器

3.id选择器

5.通配符选择器

二、复合选择器

1.后代选择器

2.子代选择器

3.并集选择器

4.交集选择器

5.:hover伪类选择器

6.结构伪类选择器


一、基础选择器

1.标签选择器

<style>
div{
color:red;
}

</style>

<body>

<div>这是标签选择器</div>

</body>

2.类选择器

​
<style>

.div1{
color:red;
}

</style>

<body>

<div class="div1">这是类选择器</div>

</body>

​

3.id选择器

1. 所有标签上都有id属性

2. id属性值类似于身份证号码,在一个页面中是唯一的,不可重复的!

3. 一个标签上只能有一个id属性值

4. 一个id选择器只能选中一个标签

​
​
​
<style>

#div1{
color:red;
}

</style>

<body>

<div id="div1">这是id选择器</div>

</body>

​

​

​

5.通配符选择器

作用:找到页面中所有的标签,设置样式

​
​
​
​
<style>

*{
font-size:30px;
}

</style>

<body>

<div >这是通配符选择器</div>

</body>

​

​

​

​

二、复合选择器

1.后代选择器

​
​
​
​
​
<style>

body div .c2{
    /* 后代选择器 */
    color: blueviolet;
}
</style>

<body>

  <div><p class="c1">后代选择器</p><p class="c2">houdai</p></div>

</body>

​

​

​

​

​

2.子代选择器

​
​
​
​
​
​
<style>
body>a{
    text-decoration: none;
}
</style>

<body>

  <a href="www.baidu.com">百度</a>
    <div id="blue">这是个id选择器</div>
    <p><a href="#">123</a></p>

</body>

​

​

​

​

​

​

3.并集选择器

​
​
​
​
​
​
​
<style>
h1,h2,h3, h4{
    /* 并集选择器 */
    color: bisque;
}
</style>

<body>

   <h1>并集选择器1</h1>
  <h2>并集选择器2</h2>
  <h3>并集选择器3</h3>
  <h4>并集选择器4</h4>
<h5>并集选择器5</h5>

</body>

​

​

​

​

​

​

​

4.交集选择器

​
​
​
​
​
​
​
​
<style>
div.d1{
    color: aqua;
}
div.d2{
    color: blueviolet;
}
</style>

<body>

 <div class="d1">666</div>
<h1 class="d2">555</h1>
<p class="d1">777</p>

</body>

​

​

​

​

​

​

​

​

5.:hover伪类选择器

​
​
​
​
​
​
​
​
​
<style>
a:hover{
    color: chartreuse;
}
  
</style>

<body>

 <a href="www.baidu.com">百度</a>

</body>

​

​

​

​

​

​

​

​

​

6.结构伪类选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    /* li:first-child{
        background-color: aquamarine;
        list-style: none;
    } */
    /* li:last-child{
        background-color: aquamarine;
        list-style: none;
    } */
    /* li:nth-child(2n+1){
        background-color: aqua;
         list-style: none;
    } */
    li:nth-last-child(2n+1){
        background-color: aqua;
         list-style: none;
    }
    </style>
</head>
<body>
 <ul>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
    <li>结构伪类选择器</li>
 </ul>   
</body>
</html>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gxbfeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值