Skip to main content

I’m embedding a Klaviyo form into my Shopify store using the Klaviyo app block. I chose the custom size option (450x200px) instead of full-width, because I want the form fields to remain centered and not stretch across the entire screen.

The layout is exactly how I want it — except the background color of the form block does not stretch full width on the live site. It leaves white margins on both sides, even though I’ve tried applying CSS like these bellow:

.klaviyo-form-container {
width: 100vw;
margin-left: calc(-50vw + 50%);
background-color: #f0f5fa;
}

<!--OR THIS-->
.klaviyo-form-container {
width: 100vw;
margin-left: calc(-50vw + 50%);
background-color: #f0f5fa;
padding-top: 3rem;
padding-bottom: 3rem;
}
<!--OR THIS-->
.klaviyo-form-container {
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
width: 100vw;
background-color: #f0f5fa;
padding-top: 3rem;
padding-bottom: 3rem;
}

 

This works in the Shopify theme editor, but not on the live site, likely because the form is rendered inside an iframe.

Shopify theme editor
live site

 

I’m not able to add custom classes or edit the .liquid file of this section since it’s generated by the app.

 

What I want:

• Keep the form at a fixed, centered size (450px wide)

• Make the background of the block stretch 100% of the screen width

 

Question:

Is there a way to achieve this layout using Klaviyo’s embedded block, without switching to full-width form mode (which stretches the fields too)? Or is there a workaround to target the block’s background outside the iframe?

 

Thanks in advance!

Hi ​@gsiq8, thanks for posting! The coding for Klaviyo app blocks can only be applied to the app block itself, so anything outside of the app block will need to be implemented using Shopify. I would recommend making a new page template on Shopify that has the specifications that you’re looking for that suit the Klaviyo app block. I hope that helps!


I did it guys!

Created a js klaviyo class in theme.liquid:

<script>
document.addEventListener("DOMContentLoaded", function () {
const klaviyoBlock = document.querySelector('[id^="shopify-block"][id*="klaviyo_email_marketing_sms_form_embed_block"]');
if (klaviyoBlock) {
const section = klaviyoBlock.closest(".shopify-section");
if (section) {
section.classList.add("klaviyo-section-bg");
}
}
});
</script>


and stylized it on main.css:

.klaviyo-section-bg {
width: 100vw;
margin-left: calc(-50vw + 50%);
background-color: #f0f5fa;
padding: 3rem 1rem;
}

 

If you are dealing with the same, hope it helps!