Mastering Responsive Section Sizes: Shopify Community Shares CSS Secrets for Mobile & Desktop

Hey there, fellow Shopify store owners! Ever found yourself scratching your head trying to make a specific section on your store look just right on both mobile and desktop? It's a classic e-commerce challenge, and it’s exactly what one of our community members, adm_zx, recently tackled in a thread that sparked insightful discussion.

adm_zx came to the community with a clear goal: they wanted to resize a particular section of their store, wearsaish.com, to be 12% on mobile devices and 50% on desktop. This isn't just about aesthetics; it's crucial for user experience. Nobody wants a massive hero banner taking up their entire mobile screen, or a tiny sliver on a large desktop monitor. Finding that sweet spot is key.

The conversation started with devcoders jumping in, asking for more context, like the store URL and screenshots. This back-and-forth is so typical of our community, where members help each other pinpoint the exact issue. adm_zx shared an image, clarifying "only this" section needed adjustment, pointing to a specific element on their homepage.

The Community's Solution: Custom CSS & Responsive Design

This is where another seasoned community member, tim_1, stepped in with an elegant solution, building on adm_zx's initial attempts. adm_zx was on the right track with media queries, but tim_1 offered key refinements for robustness and easier management.

The core of the solution revolves around using custom CSS within your Shopify theme. Specifically, tim_1 highlighted two crucial points:

  1. Overriding Styles: Sometimes, theme styles can be stubborn. To ensure your custom sizing takes precedence, you might need to use !important in your CSS property value. This tells the browser, "Hey, this style is super important, use this one!"
  2. Avoiding Cryptic IDs: Themes often generate unique, long IDs for sections (like #shopify-section-template--28779820548483__177584852133dd76f8, which adm_zx initially used). These IDs can change if you duplicate or move sections, making your CSS fragile. tim_1 wisely suggested using the "Custom CSS" setting directly within the section's settings. When you do this, Shopify automatically supplies the correct, more stable section selector for you, usually something like .section, making your code much more maintainable.

tim_1 also introduced the use of vw (viewport width) units, which is a fantastic way to maintain aspect ratio. Instead of a fixed height, setting a height relative to the viewport's width means your section scales beautifully, regardless of screen size. This is particularly useful for hero images or banners where you want the visual impact to be consistent.

Implementing Your Responsive Section Sizes

Let's put this into practice to achieve that 12% mobile and 50% desktop sizing. We'll use a combination of viewport units and media queries, following tim_1's excellent advice. While tim_1 suggested 35vw for aspect ratio, for a direct "50% of screen height" on desktop, 50vh or 50svh is what you're looking for. We'll target the requested percentages directly.

Step 1: Navigate to Your Theme Editor

In your Shopify admin, go to Online Store > Themes. Find your current theme and click Customize.

Step 2: Select the Target Section

Once in the theme editor, navigate to the specific section you want to resize. Click on the section in the left sidebar to open its settings.

image

Step 3: Add Custom CSS to the Section

Scroll down in the section settings until you find the "Custom CSS" or "Custom Liquid" box. This is exactly where tim_1's advice about avoiding cryptic IDs comes into play. By using this built-in feature, you're targeting the section correctly without needing complex selectors.

Paste the following CSS code into that box:

/* Default for mobile (screens smaller than 768px) */
.section {
    min-height: 12svh !important; /* 12% of small viewport height for mobile */
    display: flex; /* Helps content center vertically if needed */
    align-items: center; /* Centers content vertically */
    justify-content: center; /* Centers content horizontally */
}

/* Styles for desktop (screens 768px and wider) */
@media (min-width: 768px) {
  .section {
    min-height: 50svh !important; /* 50% of small viewport height for desktop */
    /* Alternative for aspect ratio based on width, like tim_1 suggested: */
    /* --section-min-height: 35vw !important; */
    /* Or for traditional viewport height: */
    /* min-height: 50vh !important; */
  }
}

A quick note on svh vs. vh: svh (small viewport height) is a newer unit that accounts for dynamic mobile browser UI elements, providing a more consistent height. vh (viewport height) is more traditional. Both work similarly, but svh can be more precise on mobile. The display: flex properties are a little extra touch to help center your section's content, which is often desired when controlling section height so precisely.

Understanding the Code & Crucial Testing

  • .section: Targets *this specific section* when placed in its "Custom CSS" box.
  • min-height: 12svh !important;: Sets the section to at least 12% of viewport height on mobile. !important overrides theme styles.
  • @media (min-width: 768px): Applies styles inside *only* for screens 768px or wider (desktop).
  • min-height: 50svh !important;: Expands the section's minimum height to 50% of viewport height on desktop, meeting adm_zx's requirement.

Remember to Save your changes!

Once saved, it's crucial to test your store on various devices. Use your browser's developer tools to simulate different screen sizes (often called "Responsive Design Mode"), and check it on actual mobile phones and tablets. This way, you can ensure that 12% on mobile and 50% on desktop looks exactly as you envisioned.

This discussion is a fantastic example of the Shopify community in action – people asking for help, experts guiding them with best practices, and everyone learning along the way. Happy customizing!

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools