Post

0102CSS选择器语法规则

CSS选择器语法

选择器实例实例描述
.class.intro选择class=”intro”的所有节点
#id#firstname选择id=”firstname”的所有节点
**选择所有节点
elementp选择所有 p 节点
element,elementdiv,p选择所有 div 节点所有p节点
element elementdiv p选择 div 节点内部的所有p节点
elementselementdiv>p选择父节点为div节点的所有 p节点
element+elementdiv+p选择紧接在 div 节点之后的所有p节点
:linka:link选择所有未被访间的链接
:visiteda:visited选择所有已被访问的链接
:activea:active选择活动链接
:hovera:hover选择鼠标指针位于其上的链接
:focusinput:focus选择获得焦点的 input 节点
:first-letterp:first-letter选择每个p节点的首字母
:first-linep:first-line选择每个p 节点的首行
:first-childp:first-child选择属于父节点的第一个子节点的所有 P节点
:beforep:before在每个p节点的内容之前插人内容
:afterp:after在每个P节点的内容之后插入内容
:lang(language)p:lang(en)选择带有以en开头的 1ang 属性值的所有P节点
element1~element2p~ul选择前面有 p 节点的所有 ul 节点
[attribute][target]选择带有 target属性的所有节点
[attribute=value][target=blank]选择 target=”blank” 的所有 节点
[attribute~=svalue][title”~=flower]选择 title 属性包含单词 flower 的所有节点
[attribute^=value]a[src^=”https”]选择 src 属性值以 https 开头的所有 a节点
[attribute$=value]a[src$=.pdf”]选择 src 属性值以 pdf 结尾的所有a节点
[attribute*=value]a[src*=”abc”]选择 src 属性值中包含 abc子串的所有a节点
:first-of-typep:first-of-type选择属于对父交节点的首个p节点的所有P节点
:last-of-typep:last-of-type选择属于对应父节点的最后一个p节点的所有p节点
:only-of-typep:only-of-type选择属于对应父节点的唯一p节点的所有p节点
:only-childp:only-child选择属于对应父节点的唯一子节点的所有p节点
:nth-child(n)p:nth-child选择属于对应父节点的第二个子节点的所有P节点
:nth-last-child(n)p:nth-last-child同上,不过是从最后一个子节点开始计数
:nth-of-type(n)p:nth-of-type选择属于对应父节点的第二个P节点的所有p节点
:nth-last-of-type(n)p:nth-last-of-type同上,不过是从最后一个子节点开始计数
:last-childp:last-child选择属于对应父节点的最后一个子节点的所有P节点
:root:root选择文档的根节点
:emptp:empty选择没有子节点的所有P节点(包括文本节点)
:target#news:target选择当前活动的 #news 节点
:enabledinput:enabled选择每个启用的 input 节点
:disabledinput:disabled选择每个禁用的 input 节点
:checkedinput:checked选择每个被选中的 input 节点
:not(selector):not选择非P节点的所有节点
::selection:selection选择被用户选取的节点部分
This post is licensed under CC BY 4.0 by the author.