Jump to content

Carousel equal Height with different aspect ratios

Go to solution Solved by Luca_,

Recommended Posts

Hi,

I want to build a corousel image gallery but when I upload images with different aspect ratio it keeps the same width and adapt the height. I want the opposite, same height and different width without cropping. I read other post but I had not find any solution. Is there any css code to do this?

page: https://www.f85.it/works/jammingpark

pw: F85website!!

Link to comment

You can use this code to Custom CSS box

section[data-section-id="668275bd2064155d7aff535d"] {
li.user-items-list-carousel__slide.list-item, .user-items-list-carousel__media-inner, .user-items-list-carousel__media-container, .user-items-list-carousel__media {
    height: 100% !important;
}}

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Ok, I found a workaround. With css I set horizontal images takes 2 columns so the aspect ratios are similar to original images (not the exact same). Just add some text in image alt section, I use "hr". Then, you have to play with columns number to make slide working correctly.

In these example my images are 3:2 and 2:3.

Here the code and image example:

li:has(img[alt~="hr"]) {
    grid-column-start: 1 !important;
    grid-column-end: 3 !important;
}
.user-items-list-carousel__slides li, .user-items-list-carousel__media-container, .user-items-list-carousel__media-inner, .user-items-list-carousel__slides img {
  height:100% !important;
  object-fit:cover;
  border-radius:20px; //use this if you want round corners
}

 

Screenshot 2024-07-04 alle 10.11.40.png

Screenshot 2024-07-04 alle 10.11.05.png

Link to comment
  • 1 month later...
  • 4 weeks later...
  • 2 weeks later...
On 9/1/2024 at 8:14 AM, aherrasti said:

Thank you for the workaround!
Any ideas on how to fix this issue?

image.thumb.png.e4fb1e62f579dbecb433543b365604ec.png

image.thumb.png.86e3382218e87a1e280d3ec11b397100.png

Setup image on carousel options to "Original size". Maybe the text under the images is creating some space.  Try to put "position" on center.

Link to comment
On 7/4/2024 at 10:19 AM, Luca_ said:

Ok, I found a workaround. With css I set horizontal images takes 2 columns so the aspect ratios are similar to original images (not the exact same). Just add some text in image alt section, I use "hr". Then, you have to play with columns number to make slide working correctly.

In these example my images are 3:2 and 2:3.

Here the code and image example:

li:has(img[alt~="hr"]) {
    grid-column-start: 1 !important;
    grid-column-end: 3 !important;
}
.user-items-list-carousel__slides li, .user-items-list-carousel__media-container, .user-items-list-carousel__media-inner, .user-items-list-carousel__slides img {
  height:100% !important;
  object-fit:cover;
  border-radius:20px; //use this if you want round corners
}

 

Screenshot 2024-07-04 alle 10.11.40.png

Screenshot 2024-07-04 alle 10.11.05.png

Another update on this workaround. There is a problem with image resolution, horizontal images are loaded as vertical image resolution so smaller than the visible resolution. I'm working on fixing this without any code injection

Link to comment
  • Solution
1 hour ago, Luca_ said:

Another update on this workaround. There is a problem with image resolution, horizontal images are loaded as vertical image resolution so smaller than the visible resolution. I'm working on fixing this without any code injection

I solved the issue. Instead of enlarge horizontal images I scaled down them. 

- Set the carousel aspect ratio to the images' vertical resolution (in my case i have 2:3 and 3:2 images so i choose 2:3)

- Set center alignment

- play with other settings as you want (should work with different spacing settings)

-  add some text in horizontal image alt section only. I used "hr".

- at this point you should see vertical images correctly but horizontal images too tall. So we have to fix them. You have to do some math. In my case i have 2:3 vertical images that have 500px height. Horizontal images have 1048,38 px height. I want horizontal images to be 500px height. The value is calculated from the css rule "padding-bottom" of a div containing the image. Originally it is setup to 150% (with carousel setup to 2:3, check this value with other resolution). We need to calculate the new padding as following:

((vertical image height) * 150) / horizontal image height

(500 * 150) / 1048,38 = 71,53895%

- add this css code:

li:has(img[alt~="hr"]) {
    grid-column-start: 1 !important;
    grid-column-end: 3 !important;
}
li:has(img[alt~="hr"]) .user-items-list-carousel__media-inner{
    padding-bottom:71.53895% !important
}

Now all the images are equal height and correct resolution!

p.s. Squarespace if you want to hire me I'm here!😁

image.thumb.jpeg.bed10b1879df7784a68efd171d41f54f.jpegimage.thumb.jpeg.97ef243fe3043aee00fd59f9b8194a8d.jpeg

Edited by Luca_
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.