How can I fill square thumbnails with photos without cropping?

Topic summary

A user wants to fill square product thumbnails with full images without cropping, while maintaining the ability to view portrait images when clicked.

Solutions Proposed:

Two community members provided CSS code solutions:

  • First approach: Add width: 100% !important; to .thumbnail--narrow img in the theme’s CSS file (base.css, style.css, or theme.css)

  • Second approach (refined): Use absolute positioning with centering transforms:

.thumbnail--narrow img {
  position: absolute !important;
  width: 100%;
  height: auto !important;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

Implementation:
Both solutions require editing the theme code through Shopify Admin → Online Store → Themes → Edit code → Assets folder → base.css file.

The user attempted the first solution but reported it wasn’t working, prompting the second, more comprehensive CSS approach with absolute positioning and centering.

Summarized with AI on November 13. AI used: claude-sonnet-4-5-20250929.

Wondering how to get the photos to fill the square thumbnails without cropping the image? I’ve seen some Shopify sites with images filling the square thumbnail but still previewing the portrait image when clicked on it.

1 Like

Hi @smander

The width size of the thumbnail is auto. But if you like to fill them with the frame it should be 100%. And it would be look like this.

This it he code I used.

From your Shopify admin dashboard, click on “Online Store” and then “Themes”.

Find the theme that you want to edit and click on “Actions” and then “Edit code”.

In the “Assets” folder, click on “base.css, style.css or theme.css” file, depending on which file your theme uses to store its CSS styles. At the bottom of the file, add the following CSS code:

.thumbnail--narrow img {
    width: 100% !important;
}

And Save.

Please don’t forget to Like and Mark Solution to the post that helped you. Thanks!

Hello @smander :waving_hand:

In Shopify Admin, go to Edit theme code, open file base.css and add this code at the bottom

.thumbnail--narrow img {
    position: absolute !important;
    width: 100%;
    height: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

The result

Hope that helps!

That looks perfect! I’ve added the code to base.css but it’s not working, any ideas?

Please replace the above code with this one

.thumbnail--narrow img {
    position: absolute !important;
    width: 100% !important;
    height: auto !important;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
1 Like