CSS各种选择器用法

li::marker{color:#ddd}
li:not(:first-child):not(:last-child):not(.third):not(#fouth){color:salmon}
ol+ol{margin-top:0}
*:before,*:after{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}
a[href]:after{content:" (" attr(href) ")"}
abbr[title]:after,.abbr[title]:after{content:" (" attr(title) ")"}
li:first-child{font-size:20px}

    <a href="http://www.baidu.com">首页</a><br>
    缩写:<abbr title="People's Republic of China">PRC</abbr><br>
    abbreviation:<span class="abbr" title="People's Republic of China">PRC</span>
    <ol>
        <li>11111</li>
        <li>22222</li>
        <li class="third">33333</li>
        <li id="fouth">44444</li>
        <li id="fifth">55555</li>
        <li>66666</li>
    </ol>
    <ol>
        <li class="item-1">11111</li>
        <li class="item-2">22222</li>
        <li class="item-3">33333</li>
        <li class="item-4">44444</li>
        <li class="item-5">55555</li>
        <li class="item-6">66666</li>
    </ol>
    <ol>
        <li class="item">11111</li>
        <li class="item">22222</li>
        <li class="item">33333</li>
        <li class="item">44444</li>
        <li class="item">55555</li>
        <li class="item">66666</li>
    </ol>
选择器 例子 例子描述 CSS
element+element div+p 选择紧接在 div 元素之后的所有 p 元素。 2
element1~element2 p~ul 选择前面有 <p> 元素的每个 <ul> 元素。 3
[attribute~=value] [title~=flower] 选择 title 属性包含单词 "flower" 的所有元素。 2
[attribute|=value] [lang|=en] 选择 lang 属性值以 "en" 开头的所有元素。 2
[attribute^=value] a[src^="https"] 选择其 src 属性值以 "https" 开头的每个 <a> 元素。 3
[attribute$=value] a[src$=".pdf"] 选择其 src 属性以 ".pdf" 结尾的所有 <a> 元素。 3
[attribute*=value] a[src*="abc"] 选择其 src 属性中包含 "abc" 子串的每个 <a> 元素。 3
:lang(language) p:lang(it) 选择带有以 "it" 开头的 lang 属性值的每个 <p> 元素。 2
:first-letter p:first-letter 选择每个 <p> 元素的首字母。 1
:first-line p:first-line 选择每个 <p> 元素的首行。 1
:first-child p:first-child 选择属于父元素的第一个子元素的每个 <p> 元素。 2
:last-child p:last-child 选择属于其父元素最后一个子元素每个 <p> 元素。 3
:before p:before 在每个 <p> 元素的内容之前插入内容 2
:after p:after 在每个 <p> 元素的内容之后插入内容。 2
:first-of-type p:first-of-type 选择属于其父元素的首个 <p> 元素的每个 <p> 元素。 3
:last-of-type p:last-of-type 选择属于其父元素的最后 <p> 元素的每个 <p> 元素。 3
:only-of-type p:only-of-type 选择属于其父元素唯一的 <p> 元素的每个 <p> 元素。 3
:nth-child(n) p:nth-child(2) 选择属于其父元素的第二个子元素的每个 <p> 元素。n: odd even number 4
:nth-last-child(n) p:nth-last-child(2) 同上,从最后一个子元素开始计数。 3
:nth-of-type(n) p:nth-of-type(2) 选择属于其父元素第二个 <p> 元素的每个 <p> 元素。 3
:empty p:empty 选择没有子元素的每个 <p> 元素(包括文本节点)。空节点:<p></p> 3
:enabled input:enabled 选择每个启用的 <input> 元素。 3
:disabled input:disabled 选择每个禁用的 <input> 元素 3
:checked input:checked 选择每个被选中的 <input> 元素。 3
:not(selector) :not(p) 选择非 <p> 元素的每个元素。 3
::selection ::selection 选择被用户选取的元素部分。 3

详细参考

猜你喜欢

转载自blog.csdn.net/weixin_42549581/article/details/114113437
今日推荐