question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Responsive sizes handling `min-width`

See original GitHub issue

Describe the bug

Hi, I would like to load a bigger image on mobile and smaller on desktop. Normally I would define on img HTML tag a min-width or if needed both min and max like so:

sizes="
  ((min-width: 50em) and (max-width: 60em)) 50em,
  ((min-width: 30em) and (max-width: 50em)) 30em,
  (max-width: 30em) 20em"

But the component accepts only max-width and it won’t work in my case, where the bigger images should be loaded on smaller screen. Currently my code looks following (smaller images are loaded on both mobile and desktop):

responsive={[
  {
    size: {
       width: Math.round(cover.width / 2),
       height: Math.round(cover.height / 2),
     },
     maxWidth: 768,
  },
  {
     size: {
      width: Math.round(cover.width / 4),
      height: Math.round(cover.height / 4),
    },
    maxWidth: 1200
  },
]}

Am I missing something or it can work as I expect it with the current implementation of Remix-Image?

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

Define in responsive prop two image sizes: for mobile bigger images should be displayed and for desktop smaller ones.

Expected behavior

I would like to defined also a min-width to display images.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tomekrozalskicommented, Jun 15, 2022

Maybe we need to sort by maxWidth instead? From the smallest to largest and values without maxWidth at the end? I created pull request: https://github.com/Josh-McFarlin/remix-image/pull/34/files

0reactions
Josh-McFarlincommented, Jun 15, 2022

@tomekrozalski Thanks for the PR! Currently relocating for work, so I’ll review it later today and hopefully push out a new release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

responsive website min-width? - UX Stack Exchange
First: You can have a great responsive site loaded with min-widths or max-widths or even mix them ...
Read more >
Setting a minimum width to fit on responsive website
The min-width will override the width value (as you would expect) when the 100% width falls below 480px.
Read more >
Responsive web design basics
A common way to deal with this problem is to give all images a max-width of 100% . This will cause the image...
Read more >
Media Query CSS Example – Max and Min Screen Width for ...
In this article, I will talk about how to use responsive design and media ... @media (min-width: 600px) and (max-width: 768px) { body ......
Read more >
min-width - CSS: Cascading Style Sheets - MDN Web Docs
The min-width CSS property sets the minimum width of an element. It prevents the used value of the width property from becoming smaller...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found