Show 2 Images at a Time in the Gallery Module Slide Layout

Written by Dan Mossop

The Divi Theme's gallery module has two layout options: grid and slider. When the slider layout is active, the gallery shows one image at a time (and you can move from one to the next with arrow buttons). If you'd like to have the gallery slider display two images at a time, this post explains how to do it.

First, here's an example of the effect we're aiming for – one gallery module in slider layout displaying two images at a time:

Show 2 Gallery Images at a Time using CSS

One way to get 2 gallery images showing at a time is to force the currently displayed slide to take up only 50% of the available width and then force the next slide to be displayed in the remaining 50% space.

To do this using CSS, first set "Gallery Settings > Advanced > CSS ID & Classes > CSS Class" to:

gallery-two-at-a-time

Then add this CSS to your site:

/* Display two gallery images */
@media only screen and (min-width: 981px) {
	
	/* Set images to 50% width */
	.gallery-two-at-a-time .et_pb_gallery_item {
		max-width: 50%;
	}
	
	/* Force display of the image after the currently displayed one */
	.gallery-two-at-a-time .et-pb-active-slide + .et_pb_gallery_item {
		display: block !important; 
		opacity: 1 !important; 
		z-index: 1 !important;
		left: 50%;
	}
	
	/* Display the first image at the end */
	.gallery-two-at-a-time .et_pb_gallery_item:first-child:not(.et-pb-active-slide) {
		display: block !important; 
		opacity: 1 !important; 
		z-index: 0 !important;
		left: 50%;
	}
}

Enhance Your Divi Galleries with Style

While you're customizing your Divi galleries, consider using the Divi Gallery Booster to add even more options to style them the way you want. Save time and impress your site visitors with breathtaking galleries, perfectly tailored to your needs.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

2 Comments

  1. Hey Dan, this is really a great tweak. I was looking for something like this to edit the gallery slider and make it look like a carousel slider. I tried to edit your css to show 3 images at a time but my skills seam to be too poor for that. Could you give me a hint possibly?

    Best regards and keep up the good work!

    Reply
    • Hey Robert, sorry I'm only just responding. I been playing around with this, but I don't think it's actually possible to modify the two images at a time CSS to work with three images. The reason is that CSS don't support rich enough logic to allow handling of the edge cases where we need to move the first and second slides to the end when the last one is active. I think a different approach will be needed, possibly using either flexbox's ordering or javascript to handle these edge cases. I'll try to spend some more time on this as soon as I can and will update here if I'm able to figure anything out. Cheers!

      Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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

We may earn a commission when you visit links on our website.