nuxt / nuxt/image

Support different aspect ratios for different screen sizes

Open
#1,466 3 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.5k
Forks
331
Avg merge
19h 52m
Merged PRs (30d)
9

Description

In my current project I need the ability to change the aspect ratio of an image, depending on the current screen size (for responsive design). I know that you can define the aspect ratio of an image by setting an explicit width and height (if you use sizes, then it is responsive):

<NuxtImg ... fit="crop" width="750px" height="375px" sizes="480px xs:550px sm:750px" />

(Using TailwindCSS)
My problem here is, that I need different aspect ratios once I hit "md" and "2xl" screen sizes. I currently solve this by using 2 more NuxtImg components, where the 2 NuxtImgs with the wrong aspect ratio for the current screen width will be hidden via display: hidden.

My idea would be to add some kind of aspect property like aspect="2/1 md:3/5" or to integrate it into the sizes property kind of like sizes="480px/240px md:450px/750px" (which would probably be a better idea) or something like that. I don't know how that could conflict with the existing height property, but if this feature could somehow work it would be really neat.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests; start by locating NuxtImg's prop handling and responsive sizing behavior. Compare the existing width, height, and sizes behavior, then define and verify responsive aspect ratios at breakpoints while preserving compatible existing usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, tailwindcss, typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.