일반 형제 결합자(~
)는 두 개의 선택자 사이에 위치하여 뒤쪽 선택자의 요소와 앞쪽 선택자 요소의 부모 요소가 같고, 뒤쪽 선택자의 요소가 뒤에 위치할 때 선택합니다. 두 요소가 서로 붙어있을 필요는 없습니다.
/* 서로 형제인 문단 중 이미지 뒤쪽인 경우에만 선택 */
img ~ p {
color: red;
}
구문
former_element ~ target_element { style properties }
예제
CSS
p ~ span {
color: red;
}
HTML
<span>이건 빨강이 아닙니다.</span>
<p>여기 문단이 있습니다.</p>
<code>그리고 코드도 있습니다.</code>
<span>이제 빨강입니다!</span>
<code>더 많은 코드가 있습니다.</code>
<span>이것도 빨강입니다!</span>
결과
명세
Specification | Status | Comment |
---|---|---|
Selectors Level 4 The definition of 'subsequent-sibling combinator' in that specification. |
Working Draft | Renames it the "subsequent-sibling" combinator. |
Selectors Level 3 The definition of 'general sibling combinator' in that specification. |
Recommendation | Initial definition. |
브라우저 호환성
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.