Taming Your Shopify Layouts: How to Perfectly Align Images and Text in Custom Sections

Hey store owners! Ever found yourself pulling your hair out trying to get an image and its accompanying text to line up perfectly on your Shopify store? You know the drill: one column is taller than the other, leaving an awkward gap, or maybe things just don't quite align horizontally. It's a super common frustration, and it's exactly what one of our community members, JustinasR, recently ran into with a custom section on their store.

The original question in the forums was all about how to "match the text box area with the image vertical height so they are the same." JustinasR had a custom section at the bottom of their page where the image was creating an unsightly gap. Let's dive into what we learned from the community and how you can tackle similar issues on your own store.

Understanding the Root Cause of Layout Gaps

Before we jump into the fixes, it's helpful to understand why these gaps appear in the first place. As our community experts, DanielAnderson and VikashJ, pointed out, this usually happens when your image column and text column are set to independent heights. Instead of stretching to match each other, they size themselves based on their own content, often leading to one being shorter than the other.

In most modern Shopify themes, sections with two columns (like an image-with-text block) typically use either Flexbox or CSS Grid for layout. The key to making them match up is often found in the parent container's CSS properties:

  • display: flex; or display: grid; on the parent.
  • align-items: stretch; on the parent container. This is crucial because it forces all direct children (your image and text columns) to stretch to the height of the tallest sibling. Often, themes might default to flex-start or center, causing those pesky gaps.

For the images themselves, you'll want to ensure they fill their container without distortion:

.your-section-class .image-column-class img {
  height: 100%;
  width: 100%;
  object-fit: cover; /* prevents distortion when height is forced */
}

As VikashJ wisely advised, using your browser's developer tools (right-click > Inspect) is your best friend here. It helps you identify the exact class names and structure of your section, which is essential for applying precise CSS.

Community-Proven Fixes for JustinasR's Custom Section

JustinasR's specific case involved a custom section, which was cleverly named sections/naujas.liquid. When you're working with custom code, you have more direct control, but it also means you're responsible for its layout. Here's how Ploqo, another helpful community member, guided JustinasR through the fixes:

1. Matching Image and Text Vertical Height (The Initial Gap)

JustinasR's original problem was a clear gap below the image because it had a fixed height, preventing it from stretching to match the text column. Here's what it looked like before:

Before: image stops short of text

The Fix (Applying to sections/naujas.liquid):

Ploqo identified that the image wrapper had a fixed height: 200px;. This needed to change. Here are the steps:

  1. Navigate to your Shopify Admin > Online Store > Themes.
  2. Find your current theme and click 'Actions' > 'Edit code'.
  3. In the left sidebar, find and open sections/naujas.liquid (or your equivalent custom section file).
  4. Locate the