次å å¼çµåå
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015å¹´7æ.
次å
å¼çµåå (next-sibling combinator, +) 㯠2 ã¤ã®ã»ã¬ã¯ã¿ã¼ãæ¥ç¶ãã 2 ã¤ç®ã®è¦ç´ ã 1 ã¤ç®ã®è¦ç´ ã®ç´å¾ã«ãã£ã¦ã両è
ãåã親è¦ç´ ã®åå士ã§ããå ´åã«ä¸è´ãã¾ãã
/* ç»åã®ç´å¾ã«æ¥ãæ®µè½ */
img + p {
font-weight: bold;
}
æ§æ
/* çµååã®åå¾ã®ç©ºç½ã¯ãªãã·ã§ã³ã§ãããæ¨å¥¨ããã¾ãã */
ç´åã®è¦ç´ + 対象ã®è¦ç´ { ã¹ã¿ã¤ã«ãããã㣠}
ä¾
>åºæ¬çãªä¾
ãã®ä¾ã¯ã次ã®å å¼è¦ç´ ãç¹å®ã®åã§ããå ´åã«é¸æããæ¹æ³ã示ãã¦ãã¾ãã
CSS
æåã® <li> ã®ç´å¾ã«ãã <li> ã®ã¿ã«ã¹ã¿ã¤ã«è¨å®ãã¾ãã
li:first-of-type + li {
color: red;
font-weight: bold;
}
HTML
<ul>
<li>One</li>
<li>Two!</li>
<li>Three</li>
</ul>
çµæ
ç´åã®å å¼ã鏿
次å
å¼çµååã¯ãç´åã®å
å¼è¦ç´ ã鏿ããããã«ã:has() æ©è½ã»ã¬ã¯ã¿ã¼å
ã«å«ãããã¨ãã§ãã¾ãã
CSS
<li> è¦ç´ ã®æ¬¡ã®å
å¼è¦ç´ ã <li> ã§ããã¤ãã®åã®ä¸ã§æå¾ã®è¦ç´ ã§ããå ´åã«ã®ã¿ã¹ã¿ã¤ã«è¨å®ãã¾ãã
li:has(+ li:last-of-type) {
color: red;
font-weight: bold;
}
HTML
<ul>
<li>One</li>
<li>Two</li>
<li>Three!</li>
<li>Four</li>
</ul>
çµæ
仿§æ¸
| Specification |
|---|
| Selectors Level 4> # adjacent-sibling-combinators> |