Jump to content

Gallery Captions & Padding between Images?

Recommended Posts

Site URL: https://smilodon-ocelot-my5f.squarespace.com/lost-america

Thanks to users on this forum, I've added gallery captions UNDER my galley images.

However, when scaling the site, the images can cover the caption above them.

Is there code to prevent this - maybe it needs percentage padding below the captions to override Squarespace's gallery settings?

passcode: trythis












Link to comment
  • Replies 6
  • Views 537
  • Created
  • Last Reply
@media screen and (max-width: 767px){
	.gallery-grid--layout-grid .gallery-grid-wrapper {
		grid-row-gap: 3vw !important;
Add this at the very bottom of the custom CSS.
Link to comment
  • 1 month later...

You can try adding the JavaScript code below which adjusts the height of the image containers to account for the caption height. Here's a video that shows a before and after when executing the code below:



(function (document) {
  var timeout;

  if (document.readyState === 'loading') {
    window.addEventListener('DOMContentLoaded', init);
  } else {

  function init() {

    setTimeout(function () {
    }, 100);

    window.addEventListener('resize', function () {
      // If there's a timer, cancel it
      if (timeout) window.cancelAnimationFrame(timeout);

      // Setup the new requestAnimationFrame()
      timeout = window.requestAnimationFrame(handleMasonryItemsCaptions);

  function handleMasonryItemsCaptions() {
    var galleries = document.querySelectorAll('.gallery-masonry');

    if (!galleries) return;

    if (isDesktop()) {
      document.querySelectorAll('.gallery-masonry-item').forEach(function (item) {
        item.style.height = '';

    galleries.forEach(function (gallery) {

      var items = gallery.querySelectorAll('.gallery-masonry-item');

      items.forEach(function (item) {
        var height = 0;
        var wrapper = item.querySelector('.gallery-masonry-item-wrapper');
        var caption = item.querySelector('.gallery-caption');

        if (wrapper) {
          height += wrapper.offsetHeight;

        if (caption) {
          caption.style.paddingBottom = 0 + 'px';
          height += caption.offsetHeight;

        item.style.height = height + 'px';

  function triggerResizeEvent() {
    var event;
    if (typeof (Event) === 'function') {
      event = new Event('resize');
    } else { /*IE*/
      event = document.createEvent('Event');
      event.initEvent('resize', true, true);

  function isDesktop() {
    return window.matchMedia('(min-width: 1024px)').matches;

  function addNodeListForEachPolyfill() {
    if (window.NodeList && !NodeList.prototype.forEach) {
      NodeList.prototype.forEach = Array.prototype.forEach;


Be sure the code above is between <script> tags, example:

  // Add JS code here


Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!

Link to comment


This topic is now archived and is closed to further replies.

  • 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.