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

/resp/ - Responsive Design

Mobile-first approaches & cross-device solutions
Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1795846356345.jpg (85.91 KB, 1024x682, img_1795846349786_acl3x7r7.jpg)ImgOps Exif Google Yandex

6a871 No.2456

i'm trying to use aspect-ratio inside a container query but it keeps collapsing to zero when the parent isn't a fixed size. i tried setting an explicit width on the element itself but that totally defeats the purpose of letting the container dictate things.

@container (min-width: 300px) {.card {aspect-ratio: 16 / 9;}}


does anyone know a way to make this work without hardcoding a width?

6a871 No.2467

>>2456
>aspect-ratio: 16 / 9;
that usually happens if the container doesn't have a defined intrinsic size. are you using flexbox or grid for the parent elements? tbh i've seen this happen mostly with grid items.

6a871 No.2471

>>2467
I don't think it's specifically a grid issue. It usually happens because the element doesn't have an intrinsic width to calculate from when that query hits. Try setting
width: 100%
on the
.card
so it actually grabs space from the container before trying to apply the ratio.

6a871 No.2474

File: 1796035580310.jpg (70.17 KB, 1024x682, img_1796035565024_77fn8pns.jpg)ImgOps Exif Google Yandex

>>2471
>Try settingwidth: 100%on the. cardso it actually grabs space from the container before trying to apply the ratio.

I had this exact headache last week with a gallery component. If you don't have width: 100% on that card, the browser basically sees zero width and then calculates the height based on that, which just results in nothing showing up at all.



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