您的位置:首页 > Web前端 > CSS

CSS3选择器

2010-12-24 17:38 92 查看
CSS3选择器原说明文档:http://www.w3.org/TR/css3-selectors/
翻 译如下,仅供参考:

*下面格式没有绘制表格,使用百度文章编辑器的三格布局,请谅解

形式
-----------------------
*
E
E[foo]
E[foo="bar"]
E[foo~="bar"]
E[foo^="bar"]
E[foo$="bar"]
E[foo*="bar"]
E[foo|="en"]
E:root
E:nth-child(n)
E:nth-last-child(n)
E:nth-of-type(n)
E:nth-last-of-type(n)
E:first-child
E:last-child
E:first-of-type
E:last-of-type
E:only-child
E:only-of-type
E:empty
E:link
E:vidited
E:active
E:hover
E:focus
E:target
E:lang(fr)
E:enabled
E:disabled
E:checked
E::first-line
E::first-letter
E::before
E::after
E.warning
E#myid
E:not(s)
E F
E > F
E + F
E ~ F
含义
-------------------------------------
任 何元素
类型为E的元素
匹配具有foo属性的元素E
匹配foo属性值为bar的元素E
匹配 foo属性值是空格分隔的多值情况时,有一个值为bar的元素E
匹配foo属性值以bar开头的元素E
匹配foo属性值以bar结尾的元 素E
匹配foo属性值中包含字符串bar的元素E
匹配foo属性值包括带有连字符“-”的情况,以en开头的元素E
文档的根元素 E
父元素中的第n个子元素E
父元素中的倒数第n个子元素E
此类型中第n个同级兄弟元素E
此类型中倒数第n个 同级兄弟元素E
父元素中首个子元素E
父元素中最后一个子元素E
此类型中首个同级兄弟元素E
此类型中最后一 个同级兄弟元素E
父元素的子元素E
此类型的同级兄弟元素E
匹配没有任何子元素(包括文本节点)的元素E
匹配具有超链接源 锚点的元素E 没有被访问(:link)
或者已经访问(:visited)
匹配元素E具有的某 些用户操作

匹配具有目标URI引用的元素E
匹配具有特定语言fr的元素E(文档语言指定了文档采用什么语言)
匹 配启用或者禁用状态的元素E

匹配处于被选中状态的元素E(比如,一个单选按钮或复选框)
匹配元素E的首行格式化
匹 配元素E的首字符格式化
匹配元素E的前面生成的内容
匹配元素E的后面生成的内容
匹配class属性是warning的元素E(文 档语言指定了class怎样被确定)
匹配id属性为myid的元素E
不匹配简单选择器s的元素E
匹配元素F是元素E的后代
匹 配元素F是元素E的子元素
匹配元素F的前面是元素E
匹配元素F的前面有元素E
说明(CSS版本)
----------------------------------
通用选择器(2)
类型选择器(1)
属性选择器(2)
属 性选择器(2)
属性选择器(2)
属性选择器(3
属 性选择器(3
属性选择器(3
属性选择器(2)
结构性伪类3
结 构性伪类(3
结构性伪类(3
结构性 伪类(3
结构性伪类(3
结 构性伪类(2)
结构性伪类(3
结 构性伪类(3
结构 性伪类(3
结 构性伪类(3
结 构性伪类(3
结 构性伪类(3
链接伪类(1)

用户操作伪类(1 和2)

目标伪类3
:lang()伪类(2)
用户界面元素状态伪类3

用 户界面元素状态伪类(3
::first-line伪类(1)
::first-letter伪 类(1)
::before伪类(2)
::after伪类(2)
Class选择器(1)
ID选择器(1)
否定伪类3
后代组合(1)
子组合(2)
相 邻兄弟组合(2)
同 级兄弟组合3
附一个CSS3选择器链接:http://www.web600.net/tool/css3_0/attribute_selectors.shtml

This section is non-normative, as it merely summarizes the following sections.

A Selector represents a structure. This structure can be used as a condition (e.g. in a CSS rule) that determines which elements a selector matches in the document tree, or as a flat description of the HTML or XML fragment corresponding to that structure.

Selectors may range from simple element names to rich contextual representations.

The following table summarizes the Selector syntax:

PatternMeaningDescribed in sectionFirst defined in CSS level
*any elementUniversal selector2
Ean element of type EType selector1
E[foo]an E element with a "foo" attributeAttribute selectors2
E[foo="bar"]an E element whose "foo" attribute value is exactly equal to "bar"Attribute selectors2
E[foo~="bar"]an E element whose "foo" attribute value is a list of space-separated values, one of which is exactly equal to "bar"Attribute selectors2
E[foo^="bar"]an E element whose "foo" attribute value begins exactly with the string "bar"Attribute selectors3
E[foo$="bar"]an E element whose "foo" attribute value ends exactly with the string "bar"Attribute selectors3
E[foo*="bar"]an E element whose "foo" attribute value contains the substring "bar"Attribute selectors3
E[hreflang|="en"]an E element whose "hreflang" attribute has a hyphen-separated list of values beginning (from the left) with "en"Attribute selectors2
E:rootan E element, root of the documentStructural pseudo-classes3
E:nth-child(n)an E element, the n-th child of its parentStructural pseudo-classes3
E:nth-last-child(n)an E element, the n-th child of its parent, counting from the last oneStructural pseudo-classes3
E:nth-of-type(n)an E element, the n-th sibling of its typeStructural pseudo-classes3
E:nth-last-of-type(n)an E element, the n-th sibling of its type, counting from the last oneStructural pseudo-classes3
E:first-childan E element, first child of its parentStructural pseudo-classes2
E:last-childan E element, last child of its parentStructural pseudo-classes3
E:first-of-typean E element, first sibling of its typeStructural pseudo-classes3
E:last-of-typean E element, last sibling of its typeStructural pseudo-classes3
E:only-childan E element, only child of its parentStructural pseudo-classes3
E:only-of-typean E element, only sibling of its typeStructural pseudo-classes3
E:emptyan E element that has no children (including text nodes)Structural pseudo-classes3
E:link
E:visited
an E element being the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited)The link pseudo-classes1
E:active
E:hover
E:focus
an E element during certain user actionsThe user action pseudo-classes1 and 2
E:targetan E element being the target of the referring URIThe target pseudo-class3
E:lang(fr)an element of type E in language "fr" (the document language specifies how language is determined)The :lang() pseudo-class2
E:enabled
E:disabled
a user interface element E which is enabled or disabledThe UI element states pseudo-classes3
E:checkeda user interface element E which is checked (for instance a radio-button or checkbox)The UI element states pseudo-classes3
E::first-linethe first formatted line of an E elementThe ::first-line pseudo-element1
E::first-letterthe first formatted letter of an E elementThe ::first-letter pseudo-element1
E::selectionthe portion of an E element that is currently selected/highlighted by the userThe UI element fragments pseudo-elements3
E::beforegenerated content before an E elementThe ::before pseudo-element2
E::aftergenerated content after an E elementThe ::after pseudo-element2
E.warningan E element whose class is "warning" (the document language specifies how class is determined).Class selectors1
E#myidan E element with ID equal to "myid".ID selectors1
E:not(s)an E element that does not match simple selector sNegation pseudo-class3
E Fan F element descendant of an E elementDescendant combinator1
E > Fan F element child of an E elementChild combinator2
E + Fan F element immediately preceded by an E elementAdjacent sibling combinator2
E ~ Fan F element preceded by an E elementGeneral sibling combinator3
The meaning of each selector is derived from the table above by prepending "matches" to the contents of each cell in the "Meaning" column.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: