CSS Subsequent-sibling (~) Combinator
Example
Select and style all <ul> elements that are preceded by a <p> element with the same parent:
p ~ ul
{
background-color: gold;
border: 1px solid gray;
}
Try it Yourself »
Definition and Usage
The subsequent-sibling combinator (~
)
matches all occurrences of element2 that follow the first element (element1).
Both element1 and element2 must share the same parent, but element2 does not have to be immediately followed by element1.
Version: | CSS3 |
---|
Browser Support
The numbers in the table specifies the first browser version that fully supports the selector.
Combinator | |||||
---|---|---|---|---|---|
element1 ~ element2 | 4.0 | 7.0 | 3.5 | 3.2 | 9.6 |
CSS Syntax