adjacent sibling combinator
(
+
) separates two selectors and matches the second element only if it
immediately
follows the first element, and both are children of the same parent
element
.
/* Paragraphs that come immediately after any image */
img + p {
font-weight: bold;
}
former_element + target_element { style properties }
li:first-of-type + li {
color: red;
}
<ul> <li>One</li> <li>Two!</li> <li>Three</li> </ul>
| 规范 | 状态 | 注释 |
|---|---|---|
|
Selectors Level 4
The definition of 'next-sibling combinator' in that specification. |
工作草案 | Renames it the "next-sibling" combinator. |
|
Selectors Level 3
The definition of 'Adjacent sibling combinator' in that specification. |
推荐 | |
|
CSS Level 2 (Revision 1)
The definition of 'Adjacent sibling selectors' in that specification. |
推荐 | 初始定义。 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Adjacent sibling combinator (
A + B
)
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 |
IE
完整支持
7
注意事项
|
Opera 完整支持 3.5 | Safari 完整支持 1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
完整支持
见实现注意事项。
Adjacent sibling combinator
General sibling combinator
Child combinator
Descendant combinator
Column combinator
: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