CSS 选择器 define the elements to which a set of CSS rules apply.
注意 : There are no selectors or combinators to select parent items, siblings of parents, or children of parent siblings.
*
ns
|*
*|*
*
will match all the elements of the document.
elementname
input
will match any
<input>
元素。
class
属性。
.
classname
.index
will match any element that has a class of "index".
id
attribute. There should be only one element with a given ID in a document.
#
idname
#toc
will match the element that has the ID "toc".
[
attr
]
[
attr
=
value
]
[
attr
~=
value
]
[
attr
|=
value
]
[
attr
^=
value
]
[
attr
$=
value
]
[
attr
*=
value
]
[autoplay]
will match all elements that have the
autoplay
attribute set (to any value).
,
is a grouping method, it selects all the matching nodes.
A
,
B
div, span
will match both
<span>
and
<div>
elements.
(space) combinator selects nodes that are descendants of the first element.
A
B
div span
will match all
<span>
elements that are inside a
<div>
元素。
>
combinator selects nodes that are direct children of the first element.
A
>
B
ul > li
will match all
<li>
elements that are nested directly inside a
<ul>
元素。
~
combinator selects siblings. This means that the second element follows the first (though not necessarily immediately), and both share the same parent.
A
~
B
p ~ span
will match all
<span>
elements that follow a
<p>
, immediately or not.
+
combinator selects adjacent siblings. This means that the second element directly follows the first, and both share the same parent.
A
+
B
h2 + p
will match all
<p>
elements that directly follow an
<h2>
.
||
combinator selects nodes which belong to a column.
A
||
B
col || td
will match all
<td>
elements that belong to the scope of the
<col>
.
:
pseudo allow the selection of elements based on state information that is not contained in the document tree.
a:visited
will match all
<a>
elements that have been visited by the user.
::
pseudo represent entities that are not included in HTML.
p::first-line
will match the first line of all
<p>
elements.
| 规范 | 状态 | 注释 |
|---|---|---|
| Selectors Level 4 | 工作草案 |
添加
||
column combinator, grid structural selectors, logical combinators, location, time-demensional, resource state, linguistic and UI pseudo-classes, modifier for ASCII case-sensitive and case-insensitive attribute value selection.
|
| Selectors Level 3 | 推荐 |
添加
~
general sibling combinator and tree-structural pseudo-classes.
Made pseudo-elements use a
::
double-colon prefix. Additional attribute selectors
|
| CSS Level 2 (Revision 1) | 推荐 |
添加
>
child and
+
adjacent sibling combinators.
添加 universal and attribute selectors. |
| CSS Level 1 | 推荐 | 初始定义。 |
见 pseudo-class and pseudo-element specification tables for details on those.
:active
:any-link
:checked
:blank
:default
:defined
:dir()
:disabled
:empty
:enabled
:first
:first-child
:first-of-type
:fullscreen
:focus
:focus-visible
:focus-within
:has()
:host()
:host-context()
:hover
:indeterminate
:in-range
:invalid
:is() (:matches(), :any())
:lang()
:last-child
:last-of-type
:left
:link
:not()
:nth-child()
:nth-last-child()
:nth-last-of-type()
:nth-of-type()
:only-child
:only-of-type
:optional
:out-of-range
:placeholder-shown
:read-only
:read-write
:required
:right
:root
:scope
:target
:valid
:visited
:where()
::-moz-progress-bar
::-moz-range-progress
::-moz-range-thumb
::-moz-range-track
::-webkit-progress-bar
::-webkit-progress-value
::-webkit-slider-runnable-track
::-webkit-slider-thumb
::after (:after)
::backdrop
::before (:before)
::cue
::cue-region
::first-letter (:first-letter)
::first-line (:first-line)
::grammar-error
::marker
::part()
::placeholder
::selection
::slotted()
::spelling-error