I’m having difficulty targeting and styling the Shopify forms teaser that appears when the Shopify forms is closed out of. This is the teaser text that displays along the bottom of the page. All attempts to target and style with CSS don’t seem to be working. I am looking to simply reduce the size of the text, change the background color, and add a border around the teaser.
My website is https://exbestia.com/
I greatly appreciate any help!
1 Like
Hello @tholland
Please share the page URL so I can check and update you.
hello, my website URL is https://exbestia.com/
Thank you!
To customize the Shopify Forms teaser on your site, you can add custom CSS to your theme. Here’s how:
- From your Shopify admin, navigate to Online Store > Themes.
2, Click Customize for your active theme.
-
In the theme editor, select Theme settings, then Custom CSS.
-
Add the following CSS code:
.shopify-form-teaser {
background-color: #f0f0f0; /* Replace with your desired background color /
color: #333; / Replace with your desired text color /
border: 1px solid #ccc; / Adjust border color as needed /
padding: 10px; / Adjust padding for spacing /
font-size: 14px; / Adjust font size as needed */
}
- Click save to apply the changes.
If your theme doesn’t have a Custom CSS option, you can add the CSS directly to your theme’s stylesheet:
- From your Shopify admin, go to Online Store > Themes.
- Click Actions > Edit code for your active theme.
- In the Assets folder, locate your main CSS file (commonly named theme.css, styles.css, or similar).
- Add the CSS code provided above at the end of this file.
- Click save to apply the changes.
unfortunately that does not seem to work when placed either in the custom CSS section or base CSS file.
The issue is that the teaser and form are both inside a shadow DOM. You have to first get the root of the shadow DOM then you can edit the content within it. The code below finds the shadow DOM and Root and then edits the teaser button. You need to place it within a mutation observer because the form and teaser are inserted into the main DOM dynamically after initially first render.
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
// Check if the added node is the specific element you're looking for
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE && node.matches('#app-embed-container-188556')) {
const shadowHost = document.getElementById('app-embed-container-188556');
const shadowRoot = shadowHost.shadowRoot;
if(shadowRoot){
const styleElement = document.createElement('style');
styleElement.textContent = `
button {
border-radius: 0 !important;
border: solid 1px black !important;
}
`;
shadowRoot.appendChild(styleElement);
}
}
});
}
});
});
const targetNode = document.body; // Or any other parent element you want to observe
const config = { childList: true, subtree: true }; // Observe direct children and descendants
observer.observe(targetNode, config);