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

Inline CSS is stretching images #57

Closed
Alfrex92 opened this issue May 24, 2019 · 14 comments
Closed

Inline CSS is stretching images #57

Alfrex92 opened this issue May 24, 2019 · 14 comments

Comments

@Alfrex92
Copy link

Alfrex92 commented May 24, 2019

Hi, in our company we have been using your library and it is working perfectly.

However, we noticed that the inline CSS is stretching the images.

squeeze-img

We wrote the css that you need to add in order to avoid this problem.

So, instead of using this


position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;

You need to add this

    position: absolute;
    left: -10000%;
    right: -10000%;
    top: -10000%;
    bottom: -10000%;
    margin: auto auto;
    min-width: 1000%;
    min-height: 1000%;
    object-fit:cover;
    -webkit-transform: scale(.1);
    transform: scale(.1);

Then, the image looks better.

scale-img

You can see a live version of the technique here: Mipon

In case that you prefer keep using the same CSS, is it possible that we can add our own css to the img?

You can check this library as a reference:
reactjs/react-tabs#148

The logic is the same, but the library allows to customize the CSS using StyledComponents.

Thanks! have a great weekend.

@bluebill1049
Copy link
Member

hey,

can you try with applyAspectRatio?

@Alfrex92
Copy link
Author

Yes, that's the prop that I'm using.

@bluebill1049
Copy link
Member

oh ok, did you supply image width and height when you are using applyAspectRatio? For aspect ratio to work, it required to having image width and height.

Yea, I think I can expose an image style prop, so you can apply your own style.

@Alfrex92
Copy link
Author

Alfrex92 commented May 27, 2019

Thanks for your quick response. Yes, I added the width and height when using applyAspectRatio. The library is working perfect. The CSS is what needs improvement.

You can replace the previous code and add this:

  position: absolute;
    left: -10000%;
    right: -10000%;
    top: -10000%;
    bottom: -10000%;
    margin: auto auto;
    min-width: 1000%;
    min-height: 1000%;
    object-fit:cover;
    -webkit-transform: scale(.1);
    transform: scale(.1);

Yess, it would be awesome if you can expose the style :D

@bluebill1049
Copy link
Member

I will expose the style for you, I will work on it this week.

@bluebill1049
Copy link
Member

@Alfrex92
Copy link
Author

Hi, thanks for adding the new feature.

How can I use it?

like this?

 <SimpleImg
        src={
          ""
        }
        imgStyle={{
          position: "absolute"
        }}
      />

@bluebill1049
Copy link
Member

Yes

@Alfrex92
Copy link
Author

@bluebill1049
Copy link
Member

https://codesandbox.io/s/lazyloadingsimplereactimg-zpcvg
fixed
react-simple-img@2.3.1

@bluebill1049
Copy link
Member

Hey,

Did you take another look? please close the issue if its resolved

thanks
bill

@oquirozm
Copy link
Contributor

@bluebill1049 this prop is super useful but I had to search through the issues to find it. Any chance it can be added to the documentation?

@bluebill1049
Copy link
Member

sure @oquirozm u want to submit a PR to update readme?

@oquirozm
Copy link
Contributor

@bluebill1049 sure, will do in a bit

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

3 participants