【CSS】选择器举例

一个简单的html例子:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="information">
        <div id="name">Zhou zhou</div>
        <div id="age">24</div>
        <p class="self-assessment">a girl who always wants to be better
            <ul class="examples">
                <li id="example1">do exercise</li>
                <li id="example2">develop interest and train specialty</li>
                <li id="example3">work hard</li>
            </ul>
        </p>
        <a href="#">if you want to know more about me</a>
    </div>
</body>

</html>
  1. ID选择器:唯一性
    #name:{ }
  2. 类选择器:选中一个或者多个
    .self-assessmen{ }
  3. 标签选择器
    div{ }
  4. 全局选择器
    *{ }
  5. 组合选择器
//任意选择器
#example1, #example2{ } //id为example1或者example2的元素
li#example1{ }  //li标签内id为example1的元素
//后代选择器,不一定是子代
#information #example3{ }
//子代选择器
.examples>example1{ }
//毗邻选择器,仅仅是对相邻的那个li起作用
#exanples+li{ }
  1. 伪类选择器
a:link{ }		// 未访问的链接 
a:visited { }	// 已访问的链接 
a:hover { }	// 鼠标移动到链接上
a:active { }	// 选定的链接
ul:first-child{ }  //ul的第一个子元素  CSS2
#information>:first-of-type{ } //id为information元素直接后代的同种元素的第一个 CSS3

CSS选择器的权重比较
单个选择器:
!important > 内联样式 > id选择器 > 类选择器 > 标签选择器 > 通配符选择器

越具体优先级越高
同样优先级写在后面的覆盖写在前面的
!important 优先级最高,但是要少用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值