CSS 关系选择器 + 接续兄弟组合器

CSS About 513 words

接续兄弟组合器 Next-sibling combinator

符号:+,使用加号表示接续兄弟组合器。

The next-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.

接续兄弟选择器(+)介于两个选择器之间,当第二个元素紧跟在第一个元素之后,并且两个元素都是属于同一个父元素的子元素,则第二个元素将被选中。

作用

第一个选择器紧挨着的下一个同级元素(兄弟元素)。

示例

h1紧挨着的第一个p(文本是123p),字体为blue

h1 + p {
    color: blue;
}

<h1>标题</h1>
<p>123</p>
<p>456</p>

参考文档

https://developer.mozilla.org/en-US/docs/Web/CSS/Next-sibling_combinator

Views: 23 · Posted: 2025-11-04

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Today In History
Browsing Refresh