選擇器 | 描述 |
---|---|
[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>