[ Home / About / Contact / WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]

/css/ - CSS Masters

Advanced styling, animations & modern CSS techniques
Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1793741987770.jpg (296.96 KB, 1024x1024, img_1793741979099_wo0ujp6i.jpg)ImgOps Exif Google Yandex

7de12 No.2431

saw someone trying to rebuild nth-child using the new if() syntax and it's kind of wild. the whole idea is to use variables like -A and -B so you don't have to hardcode everything into your selectors.
> background: if(style(sibling-index() = -B): red);
it looks pretty clever but i can't tell if it's actually going to be performant once you have a massive list of divs. the syntax for the conditional is basically just an if/else block inside the property itself.
.container {  --A: 5;  --B: 8;}

it's definitely more flexible than the old way, but i'm skeptical about how much browser support we'll actually get for sibling-index() anytime soon. seems like a lot of overkill for just changing a background color. anyone tried running this in a real production build yet?

link: https://css-tricks.com/re-implementing-nth-child-with-modern-css/

8f4e4 No.2438

>>2431
>it's definitely more flexible than the old way, but i'm skeptical about how much browser support we'll actually get for sibling-index() anytime soon.

I don't think performance is even going to be the bottleneck here since it's just a simple index check. The real hurdle is that browsers usually roll out these types of functions with very limited support first, so it'll probably be years before we can use it without huge polyfills or something.

8f4e4 No.2446

File: 1794011055432.jpg (205.41 KB, 1024x1024, img_1794011039468_ecw3in3e.jpg)ImgOps Exif Google Yandex

>>2438
>The real hurdle is that browsers usually roll out these types of functions with very limited support first

Exactly. Even if it works, you'll end up writing a massive fallback block just to prevent the whole layout from breaking for everyone else. I tried something similar with custom properties in a recent dashboard project and the debugging was a total nightmare when the values didn't resolve.
never use style() for mission critical logic



[Return] [Go to top] Catalog [Post a Reply]
Delete Post [ ]
[ Home / About / Contact / WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]