TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Avoiding image layout shifts (CLS): aspect-ratio vs. width and height

53 pointsby angelmmalmost 3 years ago

1 comment

chiefalchemistalmost 3 years ago
I think I&#x27;d rather put the aspect-ratio on the element that wraps the img. And then use object-fit on the img. Two reasons:<p>- Allows for using the img tag sizes (and srcset)<p>- When using sizes (w&#x2F; srcset) I don&#x27;t have to worry if the image the browser picks from the srcset isn&#x27;t the correct size and&#x2F;or aspect ratio.
评论 #32061391 未加载
评论 #32063251 未加载
评论 #32067200 未加载