HTML(三)选择器--复杂选择器

1、父子选择器/派生选择器

<div calss="wrapper">

    <span calss="box">123</span>

</div>

<span>456</span>

1)方式一

div span{

    background-color:red;

}

2)方式二

.wrapper span{

    background-color:red;

}

3)方式三

.wrapper .box{

    background-color:red;

}

2、直接子元素选择器

<div>

    <em>1</em>

    <strong>

        <em>2</em>

    </stong>

</div>

div > em{

    background-color:red;

}

3、选择器内核选择方式

从左到右,从右往左?

从右往左

4、并列选择器(重点)

标签、class、id、直接子元素等随便组合

组合后的选择器优先级,按照组合元素相加,权重越高,越优先;

如果权重一样,则后面代码覆盖前面代码,后来先到;

!important跟在选择器后面,则此选择器为权重最高等级;

如果选择器后面都有!important,则根据前面组合元素的权重来决定优先级。

 

div.demo{

}

 #id div p.class{

}

div .classP#idP{

}

5、分组选择器

列子:让下面标签内的元素的背景色都为红色

<body>

    <em>1</em>

    <strong>2</strong>

    <span>3</span>

</body>

方法一

em{

    background-color:red;

}

strong{

    background-color:red;

}

span{

    background-color:red;

}

方法二

em,

strong,

span{

    background-color:red;

}

转载于:https://www.cnblogs.com/xibuhaohao/p/10338837.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值