Luca_ Posted July 1 Share Posted July 1 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
tuanphan Posted July 3 Share Posted July 3 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
Luca_ Posted July 4 Author Share Posted July 4 Thanks for the reply. That code scale up the height of horizontal images but i want to keep individual aspect ratios. I have attached some pictures to explain. Link to comment
Luca_ Posted July 4 Author Share Posted July 4 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 } tuanphan 1 Link to comment
aherrasti Posted September 1 Share Posted September 1 Thank you for the workaround! Any ideas on how to fix this issue? Link to comment
Luca_ Posted 8 hours ago Author Share Posted 8 hours ago On 9/1/2024 at 8:14 AM, aherrasti said: Thank you for the workaround! Any ideas on how to fix this issue? 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
Luca_ Posted 8 hours ago Author Share Posted 8 hours ago 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 } 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 Luca_ Posted 7 hours ago Author Solution Share Posted 7 hours ago (edited) 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!😁 Edited 7 hours ago by Luca_ Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment