Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expands image when no size is set #6

Open
bryanburgers opened this issue Apr 23, 2014 · 4 comments
Open

Expands image when no size is set #6

bryanburgers opened this issue Apr 23, 2014 · 4 comments

Comments

@bryanburgers
Copy link

When using <img src="logo.png" srcset="logo.png 1x, [email protected] 2x" alt="logo"> without an explicit width or height attribute, the image is expanded to double its size, instead of staying the same size.

For example, if logo.png is 100×50 and [email protected] is 200×100, I would expect my <img> element to stay 100×50 instead of becoming 200×100.

@culshaw
Copy link
Owner

culshaw commented Apr 23, 2014

Hey, so the original image logo.png is being doubled in size irrespective of your screen density and then becoming physically 200x100?

@bryanburgers
Copy link
Author

I have a layout like this, where the blue block is an image and the gray blocks are text. The markup could be like <img src="logo.png">, without width and height attributes.

1x

If I then change the markup to be <img src="logo.png" srcset="logo.png 1x, [email protected] 2x">, the layout changes to this second layout, which is not what I expected, because the srcset polyfill is changing the intrinsic size of the image when it replaces the src.

2x

In fact, when I use Chrome, which has built in support for srcset, the first layout is correctly shown, because Chrome deals with the intrinsic size properly.

The easy fix is to change this to explicitly state the size: <img src="logo.png" srcset="logo.png 1x, [email protected] 2x" width="100" height="100">. But I think it is a bug (though I'm not sure what a polyfill could do about it), so I reported it.

@bryanburgers
Copy link
Author

Also, to more directly answer your question, this is only happening when my screen density is 2, because the polyfill is correctly downloading the 2x image and effectively turning the img into <img src="[email protected]">, which has a larger intrinsic size than <img src="logo.png">.

@culshaw
Copy link
Owner

culshaw commented Apr 24, 2014

Great explanation, I know exactly what is happening. Thanks, it's a nice edge case to have under consideration, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants