选择器 | 描述 |
---|---|
[attribute] | 用于选取带有指定属性的元素。 |
[attribute=value] | 用于选取带有指定属性和值的元素。 |
[attribute~=value] | 用于选取属性值中包含指定词汇的元素。 |
[attribute l=value] | 用于选取带有以指定值开头的属性值的元素,该值必须是整个单词。 |
[attribute^=value] | 匹配属性值以指定值开头的每一个元素。 |
[attribute$=value] | 匹配属性值以指定值结尾的每一个元素。 |
[attribute*=value] | 匹配属性值中包含指定值的每一个元素。 |
伪类 | MDN
经常使用:css
一句话总结:
!important > 行内样式 > ID选择器 > (类选择器 | 属性选择器 | 伪类选择器 )> 元素选择器html
.wrapper div > p
CSS中,浏览器查找元素是经过选择权从后往前找的, 这样作的目的是加快CSS解析速度,从后往前,排除法浏览器
input + label
背景图没选中input:checked + label
背景图选中.checkbox input{ display: none; } .checkbox input + label{ background:url(./没选中.png) left center no-repeat; background-size:20px 20px; padding-left:20px; } .checkbox input:checked + label{ background-image:url(./选中.png); }
<div class="checkbox"> <input type="checkbox" id="handsome"/> <label for="handsome">我很帅</label> </div>