Seamless Mobile UX: How to Auto-Hide Chat & Badges When Your Shopify Menu Opens
Hey there, fellow store owners! As someone who spends a lot of time digging into the Shopify community forums, I often see common frustrations pop up that many of you face. One of those recurring headaches, especially when it comes to mobile browsing, is UI clutter. You know, those moments when a crucial element like your live chat widget or a trust badge ends up obscuring your navigation menu? It's a small detail, but it can seriously impact a customer's experience.
Recently, a store owner named yonicque, using the Avante theme, brought this exact issue to the community's attention. They were looking for a way to automatically hide their chat bar and TrustedSite badge when their menu popped open, specifically to avoid that dreaded obstruction. And, as usual, the community stepped up with a fantastic, clear solution.
Tackling Mobile Menu Overlaps with Custom CSS
The core problem yonicque faced is pretty common: when a visitor opens your main menu on a mobile device (or even desktop, if your menu is a full-screen overlay), other fixed elements on the page, like a chat bubble or a trust badge, can float right over it. This isn't just an aesthetic issue; it makes your site harder to navigate and can frustrate potential customers, leading to them bouncing off your store.
Thankfully, a helpful community member, Ploqo, jumped in with a precise, step-by-step guide that nailed the fix. What's cool about this solution is that it leverages Shopify's built-in theme customization options, meaning you don't need to dive deep into complex code files or risk breaking your theme. It's all done through the "Custom CSS" section.
The Magic Behind the Fix: Understanding the Code
Before we jump into the steps, let's quickly touch on why this solution works. The trick lies in a bit of CSS (Cascading Style Sheets) that tells your browser: "Hey, if the navigation menu is open, make these other elements disappear."
Ploqo's code targets specific elements: shopify-chat (which is the default tag for the Shopify chat widget) and #trustedsite-tm-image (for the TrustedSite badge). It then uses a clever CSS selector, body:has(#mega-menu-drawer.open). This selector essentially says, "When the body element contains an element with the ID mega-menu-drawer that also has the class open (which indicates the menu is active), then apply the following styles." The display: none !important; part is crucial; it forcefully hides these elements, ensuring they don't pop up over your menu.
It's worth noting yonicque's follow-up comment, where they specifically thanked Ploqo for "correcting the Shopify chat tag as “shopify-chat”." This highlights a critical point: identifying the exact CSS selector for your chat widget or badge is key. While shopify-chat is standard, some apps or custom setups might use different IDs or classes. If you're adapting this for another element, a quick "Inspect Element" in your browser's developer tools can help you find the right selector.
Step-by-Step: Hiding Widgets When Your Menu Opens
Ready to implement this on your Avante theme (or adapt it for others)? Here’s how Ploqo laid it out:
- Head to Your Theme Editor: In your Shopify admin, go to Online Store > Themes.
- Edit Your Theme: Find your Avante theme (or your current active theme) and click the Edit theme button.
- Access Theme Settings: Click the gear icon (Theme settings) at the top left of the editor.
- Open Custom CSS: In the list of theme settings, find and click on Custom CSS.
- Paste the Code: If there’s already code in the box, simply click after the last line, press Enter for a new line, and then paste this snippet:
body:has(#mega-menu-drawer.open) shopify-chat, body:has(#mega-menu-drawer.open) #trustedsite-tm-image { display: none !important; } - Save Your Changes: Click the Save button at the top right of the editor.
And that’s it! Ploqo even included some great "before and after" images that perfectly illustrate the fix:
Before: menu open with the chat button over it
After: chat and badge hidden
You can see how clean and user-friendly the "after" picture looks. The Live chat button and the TrustedSite badge are gone when the menu is open, and they magically reappear once the menu is closed. Perfect!
Adapting This for Other Themes or Elements
While this specific code targets the Avante theme and its #mega-menu-drawer, the underlying principle is incredibly versatile. If you're using a different theme and face a similar issue, you'd simply need to identify the correct CSS selectors:
- For Your Menu: Use your browser's "Inspect Element" tool (right-click on your menu when it's open) to find the ID or class of your menu container when it's active. Look for something that indicates its "open" state. It might be
#mobile-menu.activeor.drawer-menu.is-open, for example. - For Your Widget/Badge: Similarly, inspect the chat bubble or trust badge to find its unique ID or class. Common ones are
#shopify-chat,.chat-widget, or specific IDs assigned by apps.
Once you have those, you can simply swap out #mega-menu-drawer.open, shopify-chat, and #trustedsite-tm-image in the provided CSS with your theme's specific selectors. Always test your changes in a theme duplicate first, just to be safe!
This little customization goes a long way in polishing your store's mobile experience. It shows attention to detail and helps prevent unnecessary friction for your customers. It's another great example of how tapping into the collective wisdom of the Shopify community can help us all refine our stores and deliver a better shopping journey. Keep an eye out for these small tweaks; they often make the biggest difference!





