1. PROMO Subscribe our All Access Pass @ 75% OFF & access all our 16+ premium Divi extensions: Divi Block Pro, Carousel Toolkit, etc.LEARN MORE
Dismiss Notice
NEW Divi.Help Pro Carousel AI Toolkit - Magically turn your Divi design into carousel, simply by using our online toolkit. No plugins needed. Now it works with Divi 5 as well!Try our carousel AI toolkit
BEST Divi Block - A revolutionary drag & drop tool to easily mix & match 960+ premade blocks (Light & Dark) to kick start your Divi site design. Special module designs are included as well. Also newly added AI generator & color. Now it works with Divi 5 as well!
Learn More About Divi BlockFree Version ~ 340+ Free Blocks

Solved Removing extra space when <4 images in the Gallery module

Discussion in 'Free Divi Community Forum' started by Perrine, Aug 22, 2024.

  1. Perrine

    Perrine New Member

    Is there any way to do this ? I only have 3 images in my gallery and for some reason, there's an extra space at the end that I can't remove. I'd like to center my images to the rest of the layout so it's really annoying.

    Featured : Screenshot of the issue

    Capture d’écran 2024-08-22 à 12.59.50.png
     
    1. PRO MEMBER PERKS Custom Color Scheme + Premade Layouts - A perfect combination to boost productivity:Try Now
  2. Divi Booster

    Divi Booster Divi Expert

    Hey Perrine,

    The Divi gallery module is fixed at four images per row, hence the gap. You should be able to sort it out with some CSS like this:

    Code:
    Log In or Sign Up to view this code.
    The first three rules center the gallery items. That would leave you with equal gaps at both sides. The last, optional, rule makes the images wider to fill up the entire width, eliminating the gaps entirely.

    Note that in its current form it would apply to all galleries, so you may want to replace the initial ".et_pb_gallery" on each rule with a CSS ID set on the gallery module to limit is scope.

    An alternatively way to solve the issue is with my Divi Gallery Booster plugin, which adds a range of new options to the gallery module, including the ability to set the number of images per row, and adjust their sizes and the gaps between them:

    https://divibooster.com/divi-gallery-booster/

    Hope that helps!
     
  3. Perrine

    Perrine New Member

    Unfortunately it hasn't helped, however it might just be that I got confused on where to paste this, I wasn't expecting the Gallery module to have Main item and Gallery item boxes in the custom CSS parameters. I tried both though and it has not had any visible results, also changed the Gallery ID and replaced it in the code as you recommended.

    Also thanks for recommending your own plugin, unfortunately again, I only have access to Pages on WordPress and nothing else so I won't be able to try it. I can't access the Theme options either if it ever should be needed..
     
    1. PRO MEMBER PERKS Divi Block Pro - Premade rolling text design for your Divi site without using any plugins:View Demo
  4. Divi Booster

    Divi Booster Divi Expert

    Yeah, it won't work in either of those boxes, I'm afraid, as they don't accept full CSS code like the above (only parts of it). The usual place for it would be in the Theme Options, but since you don't have access to that we can't use it, of course.

    Do you see the free-form CSS option in the gallery module settings at "Gallery Settings > Advanced > Custom CSS > Free-Form CSS"? If so, you should be able to enter it in there. If doing that, a slight improvement is the code below:

    Code:
    Log In or Sign Up to view this code.
    By using "selector" instead of ".et_pb_gallery" in the CSS rules, the style will be applied to that gallery module only and won't mess up any other galleries you may be using.

    If you can't see the free-form CSS box, or the code doesn't work in there, let me know.

    Also, no worries on the plugin - I mainly mention it as some people prefer to avoid working with code (and it's good for business, of course), but I'm always happy to help either way.
     
  5. Perrine

    Perrine New Member

    No, I'm afraid this isn't an available option on my side...I think it might not be something I can achieve with the current authorizations I have on our WordPress. I could try that again later when my authorizations are updated, and I hope it might help someone else finding this Thread. I will mark it as solved for now. Thank you a lot for trying to help me anyway, that was really nice :)
     
    1. PRO MEMBER PERKS Divi Mini Cart Pro Plugin - Instantly add 3 different types of mini cart to your Divi site:Learn More
  6. Divi Booster

    Divi Booster Divi Expert

    All is not lost, Perrine!

    While only being able to use the Main item and Gallery item boxes in the custom CSS limits us, there's still something we can do.

    The CSS boxes in this area only let you add CSS properties, not full CSS rules, and apply them to a specific element. The "Gallery Item" box can be used to add CSS properties to the ".et_pb_gallery_item" element, which lets us replicate the second and fourth rule from the CSS I gave above. The first rule we can't use, since there's no box for the ".et_pb_gallery_items" (plural) element, and the third we can't use as there's no way to target just the ":last-child" gallery item.

    But we can compensate by making the gallery images take up the full row (so that we don't need to center align them), and by setting an equal margin on either side of the gallery items (overriding Divi's normal approach of using the right margin only). That lets us get a center aligned gallery by modifying the gallery item element alone.

    Here's the CSS to place in "Gallery Settings > Advanced > Custom CSS > Gallery Item":

    Code:
    Log In or Sign Up to view this code.
    I've used CSS variables and calculations so that you can adjust the margin by modifying just the "--item-side-margin" line - everything else you can leave unaltered.

    Note that you might get an "Expected RBRACE" notice in the custom CSS box. You can safely ignore that - Divi's code editor doesn't know about CSS variables, but the browsers do and will process it correctly on the front-end.

    Hope that helps!
     
  7. Perrine

    Perrine New Member

    OMG yes it works perfectly ! Thanks so much for not giving up !
     
    1. PRO MEMBER PERKS Divi Block Pro - Powerful Divi header builder for you to mix & match premade header design, mobile menu & more:Learn More
  8. Divi Booster

    Divi Booster Divi Expert

    You're very welcome, Perrine!

    Best of luck with the rest of the site :)