Correct Portrait Aspect Ratio

Solved

Correct Portrait Aspect Ratio

rogerjet
Excursionist
38 0 3

Hi,

I am using the Dawn theme, when I select Portrait image ratio for Product card, the ratio according to the documentation supposed to be 2:3 but in fact it is not it is less than that.  So it is causing my images to be cropped when I dont want them too.

 

my website is swaace.com.au

 

Screenshot 2024-09-11 202500.jpg

 

In the screen shot above the left image is default portrait for the Theme, on the right i have forced that to 2:3 or 150%.

I dont know what to change to force all the images to be the 2:3 ratio.

 

Hope Someone has a solution for me.  I'm sure it wont be difficult just need to know what code to change.

 

Thanks

Accepted Solution (1)
BSSCommerce-B2B
Shopify Partner
1729 518 582

This is an accepted solution.

Use this one

 

<script>
function setHeightForCards() {
  const cards = document.querySelectorAll('.card__inner');
  
  cards.forEach(card => {
    const width = card.offsetWidth;
    card.style.height = (3 / 2) * width + 'px';
  });
}

document.addEventListener('DOMContentLoaded', setHeightForCards);
window.addEventListener('load', setHeightForCards);
window.addEventListener('resize', setHeightForCards);
window.addEventListener('scroll', setHeightForCards);
</script>

 

result: https://www.loom.com/share/3c316b9194fe4c08acfa2dff1e84106a

If it helps you, please like and mark it as the solution.

Best Regards 😊

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

View solution in original post

Replies 8 (8)

Tech_Coding
Shopify Partner
309 80 71

Hello @rogerjet 

You can add code by following these steps

1. Go to Online Store -> Theme -> Edit code.
2. Open your theme.liquid file

3. Paste the below code before </body> on theme.liquid
<style>
  img.motion-reduce {
      object-fit: contain !important;
   }
</style>

Tech_Coding_0-1726051228195.png

my reply helpful? Click Like to let me know!
your question answered? Mark it as an Accepted Solution.

my reply helpful? Click Like to let me know!
your question answered? Mark it as an Accepted Solution.
Shopify UI Developer
Your Coffee Tips adds a little sweetness to my day.
rogerjet
Excursionist
38 0 3

Hi thanks for the reply but that is not what I want as that display the images at whatever size they are so if the images are not all 2:3 then they are all different.

 


Screenshot 2024-09-11 204658.jpg

BSSCommerce-B2B
Shopify Partner
1729 518 582

@rogerjet ,

Step 1: Go to Shopify Admin -> Online Store ->Theme -> Edit code

Step 2: Search file theme.liquid

Step 3: Insert this code above </head> tag:

 

<style>
.product-card-wrapper  .card__inner {
   height: 100%!important
}
</style>

 

Before:

BSSCommerceB2B_0-1726051473976.png

After:

BSSCommerceB2B_0-1726051623886.png

If it helps you, please like and mark it as the solution.

Best Regards 😍

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

rogerjet
Excursionist
38 0 3

Thanks but that doesnt correct the aspect ratio in your example you can see the images are not all the same size.

BSSCommerce-B2B
Shopify Partner
1729 518 582

@rogerjet, try adding this before </body>

<script>
function setHeightForCards() {
  const cards = document.querySelectorAll('.card__inner');
  cards.forEach(card => {
    const width = card.offsetWidth;
    card.style.height = (3 / 2) * width + 'px';
  });
}
window.addEventListener('DOMContentLoaded', setHeightForCards);
window.addEventListener('load', setHeightForCards);
window.addEventListener('resize', setHeightForCards);
</script>

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

rogerjet
Excursionist
38 0 3

Sorry but that did not work either the aspect ratio still is not 2:3

BSSCommerce-B2B
Shopify Partner
1729 518 582

This is an accepted solution.

Use this one

 

<script>
function setHeightForCards() {
  const cards = document.querySelectorAll('.card__inner');
  
  cards.forEach(card => {
    const width = card.offsetWidth;
    card.style.height = (3 / 2) * width + 'px';
  });
}

document.addEventListener('DOMContentLoaded', setHeightForCards);
window.addEventListener('load', setHeightForCards);
window.addEventListener('resize', setHeightForCards);
window.addEventListener('scroll', setHeightForCards);
</script>

 

result: https://www.loom.com/share/3c316b9194fe4c08acfa2dff1e84106a

If it helps you, please like and mark it as the solution.

Best Regards 😊

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

rogerjet
Excursionist
38 0 3

Thank you so much...really fixed all my images across the site.  Strange that the Dawn theme is supposed to have portrait as 2:3 ration but is not.