はじめに結論から :is()または:where()を使うと、 これまで「前置修飾」で書かなきゃいけなかったセレクタが 「後置修飾」で書けて嬉しい! /* 通常のスタイル */ .button {} /* 特定の要素と隣接するときのスタイル */ /* こう書いてたものが */ .link + .button {} /* こう書ける */ .button:is(.link + *) {} /* 特定の要素に内包されているときのスタイル */ /* こう書いてたものが */ header .button {} /* こう書ける */ .button:is(header *) {} /* 特に、「特定のクラスの中の要素に対するスタイル」を条件分岐させるときに便利 */ .container p {} .container p:is(h2 + *) {} .container p:is(secti
![:is(), :where() を活用してCSSを「後置修飾」で書く](https://cdn-ak-scissors.b.st-hatena.com/image/square/2f14cc082397bb2e2cdebd25caea0bf82dcd0fdb/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--b4npLLOw--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3A%25253Ais%252528%252529%25252C%252520%25253Awhere%252528%252529%252520%2525E3%252582%252592%2525E6%2525B4%2525BB%2525E7%252594%2525A8%2525E3%252581%252597%2525E3%252581%2525A6CSS%2525E3%252582%252592%2525E3%252580%25258C%2525E5%2525BE%25258C%2525E7%2525BD%2525AE%2525E4%2525BF%2525AE%2525E9%2525A3%2525BE%2525E3%252580%25258D%2525E3%252581%2525A7%2525E6%25259B%2525B8%2525E3%252581%25258F%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3A%2525E3%252581%25258B%2525E3%252581%25258C%2525E3%252582%252593%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EtL0FPaDE0R2pxRzhkLXVXenp5SlJteDF3NU9tcE9KZjdkNHFHUXo5ZFowNy0wNmc9czk2LWM%3D%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)