Shopify Development

Shopify Mobile Glitches: Fixing Cut-Off 'Out of Stock' Badges with CSS

Hey there, fellow store owners! As someone who spends a lot of time diving into the Shopify community forums, I often spot recurring themes and little niggles that can really trip up even the most experienced merchants. Recently, a thread caught my eye that perfectly illustrates one of those frustrating, yet totally fixable, display issues: the dreaded "cut off" or "misshapen" out-of-stock badge on mobile devices.

It all started with a post from a store owner, vibehome, who was tearing their hair out over their "out of stock" badges looking perfectly fine on desktop, but all squished and half-hidden on mobile. Sound familiar? If you’ve ever tweaked your theme or added custom code, chances are you’ve introduced a little visual hiccup like this without even realizing it. And let’s be honest, a clean, professional look on mobile isn't just nice-to-have anymore; it’s absolutely essential for conversions and customer trust.

Browser developer tools showing CSS z-index property for an HTML element
Browser developer tools showing CSS z-index property for an HTML element

The Mystery of the Missing Badge: What's Going On?

The issue vibehome described is classic: a crucial piece of information, the "out of stock" label, wasn't displaying correctly on smaller screens. But as community member mastroke pointed out, the problem wasn't just mobile. On desktop, when hovering over products to reveal a second image, the label was also getting hidden beneath the image. This immediately signals a layering problem, which in web development, almost always points to a CSS property called z-index.

Think of z-index like stacking layers of paper on a desk. Each piece of paper has a number, and the higher the number, the closer it is to the top of the stack, making it visible over items with lower numbers. If your "out of stock" badge has a lower z-index than the product image or an overlay, it's going to disappear behind it.

Mastroke's keen eye also highlighted a potential culprit: custom code that might have been added to make the product image clickable. Often, merchants or developers wrap elements in tags for linking purposes. If this custom wrapper or another element has a higher z-index or an incorrect positioning context, it can inadvertently obscure other elements like your "out of stock" badge.

Common Causes of Overlapping Elements on Shopify

The Fix: Leveraging CSS z-index and Developer Tools

The good news is that this issue is often straightforward to fix with a little CSS adjustment. Here's how you can approach it:

Step 1: Identify the Problematic Element (The Badge)

Open your Shopify store in a web browser (preferably Chrome or Firefox) and navigate to a product page or collection page where the cut-off badge appears. Right-click on the badge (or where it should be) and select "Inspect" or "Inspect Element." This will open the browser's developer tools.

In the "Elements" tab, you'll see the HTML structure. Hover over different elements until you find the HTML code corresponding to your "out of stock" badge. Pay attention to its class names or IDs.

Step 2: Locate the Conflicting Element (The Image/Overlay)

While still in the developer tools, try to identify the element that is overlapping or hiding your badge. This is often the product image, an image overlay, or a container element that holds the image.

Step 3: Adjust the z-index

Once you've identified the badge's element, look at its computed CSS styles in the "Styles" tab of the developer tools. You're looking for the z-index property. If it's missing or set to a low number, that's your target.

As mastroke suggested, applying a higher z-index to the badge element is usually the solution. For example, if your badge element has a class like .product-badge--out-of-stock, you would add or modify its CSS:

.product-badge--out-of-stock {
  position: relative; /* z-index only works on positioned elements */
  z-index: 10; /* Use a value higher than surrounding elements, e.g., 1 or 10 */
}

Important Note: The z-index property only works on elements that have a position property set to something other than static (e.g., relative, absolute, fixed, or sticky). If your badge element doesn't have a position property, you might need to add position: relative; first.

Step 4: Implement the Fix in Your Shopify Theme

After testing the change in your browser's developer tools and confirming it resolves the issue, you need to apply it to your Shopify theme's CSS files. Here's how:

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find your current theme and click Actions > Edit code.
  3. Navigate to the Assets folder and look for files like theme.scss.liquid, base.css, custom.css, or similar stylesheet files. It's best practice to add custom CSS to a dedicated custom CSS file if your theme has one, or at the very bottom of the main CSS file.
  4. Add the CSS code you tested:
    /* Fix for out-of-stock badge visibility */
    .product-badge--out-of-stock {
      position: relative;
      z-index: 10;
    }
  5. Save your changes.

Step 5: Test Thoroughly

After saving, clear your browser cache and check your store on various mobile devices and screen sizes. Also, test the desktop hover effect to ensure the badge remains visible.

Preventative Measures and Best Practices

  • Regular Audits: Periodically review your store's mobile display, especially after installing new apps or making significant theme customizations.
  • Use Theme Customization Options: Whenever possible, use your theme's built-in customization settings rather than direct code edits, as these are often more robust and less prone to breaking.
  • Document Changes: Keep a record of any custom code you add, including where it's located and its purpose. This helps in troubleshooting later.
  • Staging Environment: For major changes, consider duplicating your theme and testing on the duplicate before publishing to your live store.
  • Professional Help: If CSS and HTML feel overwhelming, don't hesitate to reach out to a Shopify expert. Services like Shopping Cart Mover specialize in not just migrations but also optimizing your Shopify store's performance and appearance, ensuring a seamless user experience across all devices.

A flawless mobile experience is non-negotiable in today's e-commerce landscape. By understanding common display issues like the cut-off "out of stock" badge and knowing how to apply simple CSS fixes, you can maintain a professional and trustworthy storefront. If you find yourself struggling with these or other development and integration challenges, remember that expert help is just a click away at Shopping Cart Mover.

Use cases

Explore use cases

Agencies, store owners, enterprise — find the migration path that fits.

Explore use cases