Jump to content

How can I set up a Gallery that displays images in their original aspect ratios?

Go to solution Solved by iamdavehart,

Recommended Posts

choose the aspect ratio you want them to fit into then change the object-fit property in your css like so

/* add a background colour if you want (optional) */
.gallery-grid-item-wrapper {
    background:black;
}
/* change to contain (default is cover) */
.gallery-grid-item-wrapper img {
    object-fit: contain !important;
}

if you want to restrict that to a certain section or page then use the squarespace id finder extension to find the relevant id and add that before each rule.

Dave Hart. Software/Technology Consultant living in London. buymeacoffee 

Link to comment

Thanks for your suggestion. Unfortunately it doesn't seem to have changed anything. I've attached a screenshot to demonstrate the issue. The sides of the image are being cropped because its original dimensions are wider than the 16:9 aspect ratio which is currently selected for that gallery. I have images that vary in dimensions and I just want to present them in their original form within a Gallery. Is it possible?

Screenshot 2023-09-14 at 16.52.40.png

Link to comment

OK, we might just have to check whether you're using a Gallery Section or a Gallery Block. The mark-up is different.

Gallery Section

You edit your page, click Add Section, choose Image from the left hand side and pick the auto layout that looks like a grid of images. In that case, the CSS I posted above will work

/* add a background colour if you want (optional) */
.gallery-grid-item-wrapper {
    background:black;
}
/* change to contain (default is cover) */
.gallery-grid-item-wrapper img {
    object-fit: contain !important;
}

Gallery Block

If you just click Add Blank Section and then Add Block and pick Gallery you'll get a different grid which will use the css below

.slide a.image-slide-anchor {
    background:black !important
}

.slide img.thumb-image {
    inset:0 !important;
    width:100% !important;
    object-fit: contain !important;
}

results for both here, the top one is a gallery block, the bottom one is a gallery section.

image.thumb.png.05f1facf6eb1409b3c16bee4e598f30a.png

 

if it still isn't working for you then add the gallery you want to a page and share that link, as the one you've linked to in your original post doesn't have a gallery on it. or at least didn't when I first looked. 

 

Dave Hart. Software/Technology Consultant living in London. buymeacoffee 

Link to comment

Ah, I can see it take effect with the Gallery Section code. I appreciate the workaround you have provided, but I was hoping for the option to display each image in this manner, but without any empty unwanted space above and below.

If you look at the image block layout example in the attached screenshot, the images above and below it sit nicely with equal padding in between. I am guessing that this just may not be possible due to the nature of Gallery Sections?

My reason for wanting to achieve it this way instead of simply using image blocks is to ensure cohesive padding between images whilst eliminating the need to adjust the mobile layout afterwards.

If you know of a way to fulfil this, please let me know. Thanks!

Screenshot 2023-09-15 at 11.45.47.png

Link to comment
  • Solution

sure, you can do that. just put your column count to one and then override pretty much everything that squarespace do to lay it out. Because you're undoing all the things they do I'd probably only do this for specific sections by prefixing the rules with the section id as i mentioned in previous posts.

Gallery Block

div.sqs-block-gallery {
  height:auto !important;
}
.slide a.image-slide-anchor {
  background:black !important;
  padding-bottom:unset !important;
  height:auto !important;
  margin:0 !important;
  padding:0 !important;
}

.slide img.thumb-image {
    inset:0 !important;
    width:100% !important;
    height:auto !important;
    object-fit: contain !important;
  display:block !important;
}

Gallery Section

/* add a background colour if you want (optional) */
.gallery-grid-item-wrapper {
    background:black;
  padding-bottom:unset !important;
  height:auto !important;
}
/* change to contain (default is cover) */
.gallery-grid-item-wrapper img {
  	position:relative !important;
  	height:initial !important;
  	min-height:initial !important;
    object-fit: contain !important;
}

 

Dave Hart. Software/Technology Consultant living in London. buymeacoffee 

Link to comment

Hi @iamdavehart

This is unrelated to my question for this thread, but I wondered if you might be able to help with another issue I have with my Grid Galleries.

After successfully aligning my Grid Galleries to the left (by applying padding), i am still unable to add a text box to the right of them. The gallery's boundary box still stretches the full width of the site, so I'm presuming the code I need is for reducing the size of that? Or perhaps I need to remove the code I'm currently using for the gallery padding and replace it with code that focuses on the boundary box only?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

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