语法
css/* The white space around the + combinator is optional but recommended. */
former_element + target_element { style properties }
示例
基本用法
此示例演示如何选择特定类型的下一个兄弟元素。
CSS
我们只为紧跟在其类型中第一个
cssli:first-of-type + li {
color: red;
font-weight: bold;
}
HTML
html
- One
- Two!
- Three
结果
选择上一个兄弟元素
相邻兄弟组合器可以包含在 :has() 函数式选择器中,以选择上一个兄弟元素。
CSS
我们只为具有下一个兄弟元素(即其类型中最后一个
cssli:has(+ li:last-of-type) {
color: red;
font-weight: bold;
}
HTML
html
- One
- Two
- Three!
- Four
结果
规范
规范
选择器 Level 4# 相邻兄弟组合器
浏览器兼容性
加载中…
另见
后续兄弟组合器
帮助改进 MDN
此页面对您有帮助吗?
是
否
了解如何贡献 此页面由 MDN 贡献者 于 2025 年 7 月 14 日 最后修改。
在 GitHub 上查看此页面 • 报告此内容的问题