Marinus Klasen

Marinus Klasen

  • Development
  • Consultancy
  • Developer Resources
  • Blog
  • Contact

May 18, 2022

Justified auto width and height in Media Carousel Widget in Elementor

Marinus Klasen

Update: It appeared the solution below still had some horizontal scrolling/spacing issues. I’ve created a plugin to solve these.

In order to solve these issues once and for all, I’ve created a plugin that updates the Swiper instance created by Elementor.

Click here to download the plugin, or visit the Github repository

After activating the plugin, add the “auto-width” class to your Elementor component and set the image height with this custom CSS:

selector .swiper-slide img {
    height: 400px;
}

Was this helpful to you?

I’d love to hear from you! Let me know if you liked this solution via Twitter, send me an e-mail, leave a comment in the bottom of this post or star the repository on Github.

View the Github repository

Outdated information below.

The plugin I created after initially publishing this blog post will really solve the issue.

Aside from the websites and plugins I build for clients, I also work with WordPress designers & developers to customize features that themes and plugins do not have out-of-the-box.

In this case, Annika, from Team Rood, asked me if I could customize the slider so that images in the carousel would use all the height, and show in full width while respecting the image ratio.

The issue: Images do not have the same height

The solution: Images do have the same height

How was this accomplished?

Elementor allows adding custom CSS to any component you add, you can implement the fix by applying the follow custom CSS to the carousel components:

selector .swiper-slide {
    width: auto !important;
    margin-right: 9px;
    max-width: inherit !important;
}

selector .swiper-slide img {
    height: 400px;
}

Pretty easy, right?!

About Marinus Klasen

Marinus has been working in software/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge.

Marinus Klasen on Twitter

This site runs on Cloudways.
It's fast isn't it?
Cloudways offers high-quality, fast and affordable hosting.

Learn more

Need a hand? Post your project and hire me and other top notch developers on Codeable.

Hire me on Codeable

Comments

  1. Annika says

    May 19, 2022 at 11:03 am

    My client and I are very happy with your help Marinus! This is exactly what we were looking for.

    Reply
  2. blickwerker says

    June 29, 2022 at 3:46 pm

    Thank you for sharing your solution, that was exactly what i was looking for to access the Elementor swiper params.

    Reply
  3. Bram says

    October 4, 2022 at 7:57 am

    I’ve been looking for this for some time now. Does this also eliminate the problem of unevenly height images in the slider? That doesn’t work in Elementor. The images are skewed.

    Reply
    • Marinus Klasen says

      October 9, 2022 at 11:11 am

      Yes, but you do have to add a bit of CSS for that, see the top of the post for a code snippet!

      Reply
  4. Martina says

    October 11, 2022 at 11:43 am

    The code works for me. The plugin does not, so I am very grateful for the above code. As a photographer the way my images are presented is very important. Huge thanks Marinus!

    Reply
    • Marinus Klasen says

      October 11, 2022 at 11:52 am

      Hi Martina,

      Thanks for letting me know! Could you let me know what doesn’t work in the plugin?

      / Marinus

      Reply
  5. Karen says

    October 21, 2022 at 5:12 am

    Thanks for saving me Marinus, this is exactly what I’ve been looking for! I have some feedback for you too – I installed plugin but ended up using your original code. With your updated code the horizontal images were distorted as they were compressed to same width as portrait images. I would also like to know if you are able to modify the original code to include height conditions for responsive versions? I hope you can help!
    Cheers, Karen

    Reply
  6. Fabiola says

    November 11, 2022 at 1:21 am

    I have downloaded and activated the plugin. Now what? how can i add it to my website? is there a specific widget i need to add (please name it).

    Reply
    • Marinus Klasen says

      November 18, 2022 at 4:18 pm

      Hi Fabiola, this plugin assumes you’re using the Media Carousel Widget as well, more info here: https://elementor.com/help/media-carousel-widget-pro/

      Reply
  7. Johannes says

    November 14, 2022 at 11:33 am

    Thanks for your plugin! It works, but there is kind of a “bug”.
    With the pure image carousel, the images are aligned to the left side of the slider.
    When using your plugin, the dynamic image width works as expected, but the images get cut off on the left side.
    It seems, that the slider slides always the same amount of pixels. It would be very useful, if the plugin had an option to slide always the corresponding width of the most-left-visible image.

    Reply
    • Marinus Klasen says

      November 18, 2022 at 4:17 pm

      hmmm – not sure if I fully understand the issue, can you share a link to your website via e-mail?

      Reply
  8. Francesco says

    February 4, 2023 at 3:30 pm

    Hello does this work without Elementor Pro?

    Reply
    • Marinus Klasen says

      February 6, 2023 at 11:07 am

      Quite sure it does!

      Reply
  9. Steve K says

    February 6, 2023 at 4:53 am

    Thank you Marinus for this awesome plugin! I was looking for something totally unrelated and stumbled across this – It helped me solve a problem I hadn’t started looking at. Love it when that happens.
    This will be used a lot and just wanted to say thank you for sharing it.

    Reply
  10. Jacqueline Cote says

    February 7, 2023 at 8:53 pm

    Thank you so much for this! I am building a dynamic site and need clients to be able to upload without worrying about aspect ratios! 🙂

    I do have one question… it seems that there is space at the end of the carousel.. maybe because it’s calculating the width that would be there? Is there a way to get rid of that so that the carousel is seamless?

    Here’s a link to a very rough development site: http://wptesting1.flourishdesignstudio.com/member-directory-february/2/single-winery-profile/

    Reply
    • Marinus Klasen says

      February 13, 2023 at 11:43 am

      The link you shared results in a 404 – feel free to contact me by e-mail 🙂

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Ready to take action?

I'm looking forward to discuss your projects and goals!
Feel free to reach out using the contact details below.

Marinus Klasen

[email protected]
twitter.com/marinusklasen
linkedin.com/in/marinusklasen

  • GitHub
  • LinkedIn
  • Twitter

Have you read?

  • Storing private data with SSH on WPEngine sitesDecember 15, 2022
  • Get the HTML content of a block edit page or post in WordPressNovember 30, 2022
  • Rename Coupon code text to Discount code in WoocommerceNovember 3, 2022
  • Background-size cover in mPDFOctober 22, 2022
  • WordPress.com SSH & duplicating a WordPress.com website locallyOctober 11, 2022

Copyright © 2023 · Marinus Klasen | Webdesign by Team Rood