[ 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: 1792617234082.jpg (130.5 KB, 1024x1024, img_1792617226323_o9pw7rgi.jpg)ImgOps Exif Google Yandex

0aae5 No.2361

Been messing around with this trick to trigger styles based on how much of an element is actually visible in the viewport. It's way better than trying to use a bunch of messy intersection observers for simple things like hiding shadows or shrinking a header. I tried it on a sticky sidebar today and it worked like a charm without any heavy lifting. Just gotta make sure your container setup is right or it won't trigger properly.
@container (scrollport(0% 100%)) {.card {opacity: 0;}}

It feels a bit like magic when the layout shifts perfectly as you scroll past. I was using heavy JS much lighter CSS for this instead.

0aae5 No.2375

File: 1792831428213.jpg (103.63 KB, 1024x1024, img_1792831412531_3xnl9at8.jpg)ImgOps Exif Google Yandex

>>2361
>I was using heavy JS much lighter CSS for this instead.

yeah, i ditched my intersection observer setup for a similar trick on a product gallery last week. just watch out for the browser support on 'scrollport' if you're still supporting older safari versions. it's basically dead for anyone not on latest builds

0aae5 No.2378

>>2375
>it's basically dead for anyone not on latest builds

true but i still use a fallback @supports (container-type: size) {. } just to be safe. also the moment you try to use this with nested containers without a proper setup it just breaks everything.

0aae5 No.2384

File: 1792961001733.jpg (129.04 KB, 1024x1024, img_1792960987186_s9t4fksx.jpg)ImgOps Exif Google Yandex

>>2378
>the moment you try to use this with nested containers without a proper setup it just breaks everything.

I've run into that too, especially when the parent container has its own overflow settings messing with the calculation. If you can't avoid the nesting mess, just wrap your component in a dedicated stable wrapper with
container-type: inline-size
to keep the scope predictable for the scrollport check.



[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 ]