gallery image not fitting every mobile screen

Solved

gallery image not fitting every mobile screen

Domisana
Excursionist
31 0 8

WhatsApp Image 2025-01-09 at 13.49.57_47a1300e.jpg

My website is domisana.com, I had problems with image gallery slider it was cropping photos on different mobile devices differently, I always upload square 1:1 but aspect ratio was changing depending on the mobile screen you view at.

 

Then I inserted the CSS code 

.product__media img { object-fit: contain !important; }

 

and now image is not cropped anymore but I have these white lines on the side depending on the mobile device I am viewing it at (for example iPhone 13 pro max works ok)

 

tell me is there some code to fix this, make image always appear in square aspect ratio 1:1 not crop it or stretch depending on the mobile device

Accepted Solution (1)

Ahmad31
Shopify Partner
224 21 37

This is an accepted solution.

Ahmad31_0-1736429208437.png

 

.product__media.media.media--transparent {
    position: relative;
    width: 100%; /* Adjust width as per your layout */
    padding-top: 100%; /* Ensures a 1:1 aspect ratio */
    overflow: hidden;
}

.product__media.media.media--transparent img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

 

Replace your code with this code

Love my work? Buy Me A Coffee
Hire Me: Email me Or Chat on Whatsapp
If you found my solution helpful, please like and accept it. Your support is greatly appreciated!

View solution in original post

Replies 6 (6)

Moeed
Shopify Partner
7731 2074 2554

Hey @Domisana 

 

Replace your code with this code

.product__media img {
    object-fit: fill !important;
}

RESULT:

Moeed_0-1736427859511.png

 

If I managed to help you then, don't forget to Like it and Mark it as Solution!

 

Best Regards,
Moeed

- Need a Shopify Specialist? Chat on WhatsApp

- Get a quick Shopify quote – Click here!

- Custom Design | Advanced Coding | Store Modifications


Domisana
Excursionist
31 0 8

i dont want to stretch images, but to keep original aspect ratio, command fill only stretches and ruins image, is there another solution?

Ahmad31
Shopify Partner
224 21 37

This is an accepted solution.

Ahmad31_0-1736429208437.png

 

.product__media.media.media--transparent {
    position: relative;
    width: 100%; /* Adjust width as per your layout */
    padding-top: 100%; /* Ensures a 1:1 aspect ratio */
    overflow: hidden;
}

.product__media.media.media--transparent img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

 

Replace your code with this code

Love my work? Buy Me A Coffee
Hire Me: Email me Or Chat on Whatsapp
If you found my solution helpful, please like and accept it. Your support is greatly appreciated!
Domisana
Excursionist
31 0 8

Thanks so much it works!!!

Ahmad31
Shopify Partner
224 21 37

You're welcome! @Domisana  Glad it worked for you. A coffee would definitely fuel more helpful solutions like this! 😉

Love my work? Buy Me A Coffee
Hire Me: Email me Or Chat on Whatsapp
If you found my solution helpful, please like and accept it. Your support is greatly appreciated!

websensepro
Shopify Partner
2137 267 318

Hi @Domisana 

1. Go to Online Store -> Theme -> Edit code.
2. Open your theme.css / based.css file and paste the code in the bottom of the file.

.product-media-container.constrain-height {
    min-height: 100vw !important;
}

Result:

websensepro_0-1736429686741.png

 

If my reply is helpful, kindly click like and mark it as an accepted solution.
Thanks!

Need a Shopify developer? Hire us at WebSensePro For Shopify Design Changes/Coding
For Free Tutorials Subscribe to our youtube
Get More Sales Using Big Bulk Discount APP
Create Your Shopify Store For Just 1$/Month
Get More Sales Using Big Bulk Discount APP