2020-10-04

    科技2022-07-14  140

    新增选择器:

    选择器: 例子 描述 element>element div>p 选择 <div>的 子元素<p> 。 element+element div+p 选择在 <div> 元素之后的相邻的 <p> 元素。 element~element div~p 选择在 <div> 元素之后的所有 <p> 元素。 属性伪类: [attribute] [target] 选择带有 target 属性所有元素。 [attribute=value] a[target=_back] 选择 target="_blank" 的所有元素。 [attribute~=value] [title~=main] 选择 title 属性包含单词 "flower" 的所有元素。 [attribute^=value] a[class^="test"] 选择其 a属性值以 "test" 开头的每个 <a> 元素。 [attribute$=value] a[class$="text"] 选择其 a属性以 "text" 结尾的所有 <a> 元素。 [attribute*=value] a[src*="abc"] 选择其 src 属性中包含 "abc" 子串的每个 <a> 元素。 :focus input:focus 选择获得焦点的 input 元素。 结构伪类: :first-letter p:first-letter 选择每个 <p> 元素的首字母。 :first-line p:first-line 选择每个 <p> 元素的首行。 :first-child p:first-child 选择属于父元素的第一个子元素的每个 <p> 元素。 :first-of-type p:first-of-type 选择属于其父元素的首个 <p> 元素的每个 <p> 元素。 :last-of-type p:last-of-type 选择属于其父元素的最后 <p> 元素的每个 <p> 元素。 :only-of-type p:only-of-type 选择属于其父元素唯一的 <p> 元素的每个 <p> 元素。 :only-child p:only-child 选择属于其父元素的唯一子元素的每个 <p> 元素。 :nth-child(n) p:nth-child(2) 选择属于其父元素的第二个子元素的每个 <p> 元素。 :nth-last-child(n) p:nth-last-child(2) 同上,从最后一个子元素开始计数。 :nth-of-type(n) p:nth-of-type(2) 选择属于其父元素第二个 <p> 元素的每个 <p> 元素。 :nth-last-of-type(n) p:nth-last-of-type(2) 同上,但是从最后一个子元素开始计数。 :last-child p:last-child 选择属于其父元素最后一个子元素每个 <p> 元素。 **比较:nth-child与nth-of-type的区别? 前者不指定类型,后者指定类型 其它: :target p:target 目标选择器,跟锚点链接一起使用 伪元素: :before p:before 在每个 <p> 元素的内容之前插入内容。 :after p:after 在每个 <p> 元素的内容之后插入内容。

    结构选择器

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> /*li:first-child{ color: red; }*/ /*li:last-child{ color: red; }*/ /*li:first-letter{ color: red; }*/ /*li:first-line{ color: red; }*/ /*-------------------------------------------------------*/ /*li:first-of-type{ color: green; } li:first-child{ color: red; }*/ /*li:last-child{ color: red; }*/ /*li:last-of-type{ color: green; }*/ /*p:only-of-type{ color: pink; }*/ /*p:only-child{//父元素里面有且只有一个p标签元素,有其他元素就没有效果 color: red; }*/ </style> </head> <body> <div> <p>22222222</p> </div> <ul> <p>111111111111111</p> <li>哈哈哈哈<br>斤斤计较</li> <li>呵呵呵呵</li> <li>嘿嘿嘿嘿</li> <li>嘤嘤嘤嘤</li> <li>啦啦啦啦</li> <li>吼吼吼吼</li> <li>咕咕咕咕</li> <li>咯咯咯哒</li> <li>叽叽叽叽</li> <h1>999999999999</h1> </ul> </body> </html> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> /*li:nth-child(9){ color: red; }*/ /*li:nth-child(even){ color: red; }*/ /*li:nth-child(odd){ color: red; }*/ /*li:nth-child(9){ color: red; }*/ /*-----------------------------*/ /*li:nth-of-type(9){ color: pink; }*/ /*li:nth-of-type(even){ color: pink; }*/ /*--------------------------------*/ /*倒数的n个li变颜色*/ /*li:nth-last-of-type(4){ color: blue; }*/ /*li:nth-last-child(1){ color: blue; }*/ </style> </head> <body> <ul> <li>哈哈哈哈<br>斤斤计较</li> <li>呵呵呵呵</li> <li>嘿嘿嘿嘿</li> <li>嘤嘤嘤嘤</li> <li>啦啦啦啦</li> <li>吼吼吼吼</li> <li>咕咕咕咕</li> <li>咯咯咯哒</li> <p>44444444444444</p> <li>叽叽叽叽</li> </ul> </body> </html>

    目标选择器

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> div:target{ color: red; font-size: 30px; } </style> </head> <body> <a href="#music">音乐</a> <a href="#vedio">电影</a> <a href="#txt">小说</a> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <div id="music"> <p>林俊杰</p> <p>周杰伦</p> <p>老秦</p> </div> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <div id="vedio"> <p>战狼2</p> <p>世界大战</p> <p>老秦</p> </div> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <p>。。。。。。。。。。。。。。。。</p> <div id="txt"> <p>鬼吹风</p> <p>盗墓笔记</p> <p>是怎样炼成的厚脸皮</p> </div> </body> </html>
    Processed: 0.009, SQL: 8