SOLVED

Re: Email Template Background Image and Transparency

Go to solution
kenmckown
Level 4

I am building out a master email template, and one of the modules I want to create has a background color (that needs to be transparent) as well as a background image with text overlaying it. I want to know if I can build the transparent color and image as variables into the template so these can be set via the email editor.

 

Here is the current CSS I am using to achieve this:

 

<style>
      			.transparentbg {
                  background-image: linear-gradient(rgba(84, 86, 90, .85), rgba(84, 86, 90, .85)), url('https://go.autoshopsolutions.com/rs/180-DGD-014/images/Layer 1.png?version=0');
                  background-size: cover;
                  background-color: #54565A;
                  width: 640px;
                  height: 300px;
          		@media screen and (max-width:640px) {
                  .block { display: block !important; width: 100% !important; } 
                }
      	</style>

And here is my table for the module:

<!-- Transparent Banner Image -->
								<table class="mktoModule" mktoName="Full Width Image Section" id="full-width-img-section-transparent" width="100%" cellpadding="0" cellspacing="0" border="0" align="center" style="width: 100%!important;height:300px;margin: 0 auto;border-spacing: 0;border-collapse: collapse;background-image:${BannerSection-Bg}">
									<tr>
										<td class="transparentbg" align="center" valign="top" style="vertical-align:middle;text-align:center;">
											<div class="mktoText" id="TransparentText1" mktoname="Text" style="color: #ffffff; font-size: 30px; font-weight: bold;">LOREM IPSUM</div>
                                          	<div class="mktoText" id="TransparentText2" mktoname="Text" style="color: #ffffff; font-size: 30px; font-weight: bold;">DOLOR SIT AMET!</div>
                                          	<p class="mktoText" id="TransparentText3" mktoname="Text" style="color: #ffffff; font-size: 17px; font-weight: none;">LOREM IPSUM DOLOR SIT AMET CONSECURETU</p>
										</td>
									</tr>
								</table>
								<!-- Transparent Banner Image End -->
1 ACCEPTED SOLUTION
Dave_Roberts
Level 10

The CSS background property has just about the same support as the background-image and background-color  in email: https://www.caniemail.com/search/?s=background so you might be able to get away with consolidating your CSS a bit to look something like:

 

<style>
.transparentbg { 
  background: #54565A linear-gradient(rgba(84, 86, 90, .85), rgba(84, 86, 90, .85)), url('https://go.autoshopsolutions.com/rs/180-DGD-014/images/Layer 1.png') cover;
  width: 640px;
  height: 300px;
}

@media screen and (max-width:640px) {
  .block { display: block !important; width: 100% !important; } 
}
</style>

 

Check out the syntax for "background" here: https://www.w3schools.com/cssref/css3_pr_background.php

 

To make this editable, you'd want to setup some variables like Jo mentioned, and that might look something more like this:

 

<head>

  <meta class="mktoString" id="SectionID-bg-color" mktoName="Section: BgColor" default="#54565A" mktoModuleScope="true">
  <meta class="mktoString" id="SectionID-bg-gradient-1" mktoName="Section: BgGradient 1" default="rgba(84, 86, 90, .85)" mktoModuleScope="true">
  <meta class="mktoString" id="SectionID-bg-gradient-2" mktoName="Section: BgGradient 2" default="rgba(84, 86, 90, .85)" mktoModuleScope="true">
  <meta class="mktoString" id="SectionID-bg-image" mktoName="Section: BgImage" default="#54565A" mktoModuleScope="true">

  <style>
  .transparentbg { 
    background: ${SectionID-bg-color} linear-gradient(${SectionID-bg-gradient-1}, ${SectionID-bg-gradient-1})), url('${SectionID-bg-image}') cover;
    width: 640px;
    height: 300px;
  }
  @media screen and (max-width:640px) {
    .block { display: block !important; width: 100% !important; } 
  }
  </style>

</head>

 

 

If you consolidate the CSS or not, the idea is about the same, just setup some variables like in the example above and then add those into your CSS in place of the actual values. An important note about the setup here is that you'll want to have your <meta> tags for the variable come before the <style> tag in the <head>.

 

For the "SectionID" part of the variable ID and the "Section: " in the mktoName, those can be optional but helpful to the end user to understand where these changes will occur. So something like "Banner-bg-color" (where the id of the module is "Banner") and then "Banner: BgColor" for the mktoName so that the end user can see which section/module this is associate with.

 

For the mktoModuleScope, I'm assuming this is for a module so it's set to "true" but it's not for a module you can change it to "false" to make these variables appear in the global scope rather than within the module editor controls. 

View solution in original post

12 REPLIES 12
Dave_Roberts
Level 10

The CSS background property has just about the same support as the background-image and background-color  in email: https://www.caniemail.com/search/?s=background so you might be able to get away with consolidating your CSS a bit to look something like:

 

<style>
.transparentbg { 
  background: #54565A linear-gradient(rgba(84, 86, 90, .85), rgba(84, 86, 90, .85)), url('https://go.autoshopsolutions.com/rs/180-DGD-014/images/Layer 1.png') cover;
  width: 640px;
  height: 300px;
}

@media screen and (max-width:640px) {
  .block { display: block !important; width: 100% !important; } 
}
</style>

 

Check out the syntax for "background" here: https://www.w3schools.com/cssref/css3_pr_background.php

 

To make this editable, you'd want to setup some variables like Jo mentioned, and that might look something more like this:

 

<head>

  <meta class="mktoString" id="SectionID-bg-color" mktoName="Section: BgColor" default="#54565A" mktoModuleScope="true">
  <meta class="mktoString" id="SectionID-bg-gradient-1" mktoName="Section: BgGradient 1" default="rgba(84, 86, 90, .85)" mktoModuleScope="true">
  <meta class="mktoString" id="SectionID-bg-gradient-2" mktoName="Section: BgGradient 2" default="rgba(84, 86, 90, .85)" mktoModuleScope="true">
  <meta class="mktoString" id="SectionID-bg-image" mktoName="Section: BgImage" default="#54565A" mktoModuleScope="true">

  <style>
  .transparentbg { 
    background: ${SectionID-bg-color} linear-gradient(${SectionID-bg-gradient-1}, ${SectionID-bg-gradient-1})), url('${SectionID-bg-image}') cover;
    width: 640px;
    height: 300px;
  }
  @media screen and (max-width:640px) {
    .block { display: block !important; width: 100% !important; } 
  }
  </style>

</head>

 

 

If you consolidate the CSS or not, the idea is about the same, just setup some variables like in the example above and then add those into your CSS in place of the actual values. An important note about the setup here is that you'll want to have your <meta> tags for the variable come before the <style> tag in the <head>.

 

For the "SectionID" part of the variable ID and the "Section: " in the mktoName, those can be optional but helpful to the end user to understand where these changes will occur. So something like "Banner-bg-color" (where the id of the module is "Banner") and then "Banner: BgColor" for the mktoName so that the end user can see which section/module this is associate with.

 

For the mktoModuleScope, I'm assuming this is for a module so it's set to "true" but it's not for a module you can change it to "false" to make these variables appear in the global scope rather than within the module editor controls. 

kenmckown
Level 4

Thanks so much for this, one thing I am noticing when coding it, is the transparency is not working when using the variable. It creates a string, but even with it coded, it has the background a solid color. If I hard code it, it works. Also is not something I can use without a string, most people are not going to know RGB color wheels.

Jo_Pitts1
Level 10 - Community Advisor

@kenmckown ,

what does your string look like.  Also, what does the rendered CSS/HTML look like when you are in preview mode?

 

Don't forget also to consider the VML you'll need to at least get text with background image working in Outlook.  If you google, you'll find examples.  Once you've had a crack and if you've not quite got there, I'm happy to help try and get you over the line.

 

Cheers

Jo

kenmckown
Level 4

This is what my variables look like:

kenmckown_0-1713555467741.png

 

I was hoping to be able to pick a color and transparency level without having to input specific strings.

Dave_Roberts
Level 10

You aren't going to get any love from Microsoft (Outlook) on a PC in the transparency department b/c .... Microsoft 😞

 

Here's a look at the support charts for both the RGBA color codes and the "opacity" CSS property:

RGBA Support:

https://www.caniemail.com/features/css-rgba/

Dave_Roberts_0-1713802846691.png

 

Opacity Support:

https://www.caniemail.com/search/?s=opacity

Dave_Roberts_1-1713802875763.png

 

If you have to have a transparent color in the background, it might be best to use images that have the transparency baked into the image instead. The tradeoff with this is that you'll need specific background colors and can't just make one up on the fly (but it sounds like that'd be a challenge for the end users anyway). To get something like this setup with the end user in mind, I'd probably create a handful of images that are transparent versions of the background colors you'd want to work with.

For example, lets say your brand colors are orange and blue, here's a rundown of the images I'd create and how I'd name them:
1x Orange at 25%, 50%, 75% | bg-orange-25.png | bg-orange-50.png | bg-orange-75.png
1x Blue at 25%, 50%, 75% | bg-blue-25.png | bg-blue-50.png | bg-blue-75.png

1x White at 25%, 50%, 75% | bg-white-25.png | bg-white-50.png | bg-white-75.png

1x Black at 25%, 50%, 75% | bg-black-25.png | bg-black-50.png | bg-black-75.png

 

From here, you can use the mktoList variable rather than the mktoString variable to create a more defined list (closed input vs open input) to match up with your background image naming convention. I might make one mktoList variable for the color name (orange, blue, white, black) and another for the percent of transparency (25, 50, 75).

 

Here's a link to the Email Syntax documentation for the mktoList variable: https://experienceleague.adobe.com/en/docs/marketo/using/product-docs/email-marketing/general/email-...

 

That'd look something like this in code:

<meta class="mktoList" id="bg-transparent-color" mktoName="BG: Color" values="orange, blue, white, black" default="orange" mktoModuleScope="true">

<meta class="mktoList" id="bg-transparent-value" mktoName="BG: Transparency %" values="25, 50, 75" default="50" mktoModuleScope="true">

 

Then when you put this into play, you'd want to kind of combine the variables into the background URL string to queue off of the variables above, here's a very basic example using just the background property, but you'd want these to match up with your current code (just update the image URL to match something like this format):

<table style="background: url(https://domain.name.com/rs/###-XXX-###/images/bg-${bg-transparent-color}-${bg-transparent-value}.png);">
...
</table>

<!-- rendered code below w/ default variables from above -->
<table style="background: url(https://domain.name.com/rs/###-XXX-###/images/bg-orange-50.png);">
...
</table>

 

In the end, something like this would present the end user with two handles to control the background "color" (image) and opacity to make a more limited set of changes without needing to know any fancy RGBA stuff. 

kenmckown
Level 4

I was just about to ask this question, so it seems images are the best way to go for transparency for Outlook. Also can you have a background image, then text, and then overlay the transparent image, basically three layers. Or will that cause issues?

Dave_Roberts
Level 10

As far as I know you can layer multiple background images using the background CSS property, it's just a matter of how you write the CSS value for it. Here's a website with an example of multiple backgrounds:
https://www.w3schools.com/css/css3_backgrounds.asp

Dave_Roberts_0-1713817142559.png

Notice that you can write them as independent properties (image, position, repeat, etc) which work as a comma-separated list or you can combine them into a single background property where the two pieces are comma-separated and the individual background properties are separated by a space. 

There are more properties available within the background property which you can find examples of here:
https://www.w3schools.com/cssref/css3_pr_background.php
Here's a look at the syntax order for "all the things" you can couple into a single background value:

background: bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;

 If you had multiple background images, you'd just add a comma to the end of this first set of properties and add in the properties for the 2nd image.

 

In terms of creating a 3-layer stack, I'd recommend that you set it up as a multiple-background image -- bottom layer w/ the image, top layer with the transparent overlay and then have the live text sit on top of the background image in the container itself. You could theoretically set up 3 different background images if one of them contained the text (then it would go on the top layer instead) and you'd just add that onto the background property with another comma-separated value for the property. It's not really best practice to include text as an image in the banner for a lot of reasons but it should work in a pinch if you're required to go that route.

Jo_Pitts1
Level 10 - Community Advisor

@kenmckown ,

That should work just fine (I'm assuming there is an 'R' at the front of the BG gradient string).

If it isn't, then you need to review how the HTML looks once rendered.  Go to preview, do an inspect, and see what's going on.  It won't be a Marketo thing per se.

 

Also, remember that Outlook app for windows doesn't support the alpha channel, and doesn't (from memory) even recognise rgba as a colour format.

 

@SanfordWhiteman and I put some work in a while back on translating rgba to hex.  He did a blog post on it (here).  My original motivation was to allow a graceful fall back from rgba to something Outlook could understand.

 

Cheers

Jo

 

 

Jo_Pitts1
Level 10 - Community Advisor

@kenmckown ,

yes - you can do a 'fall back' colour

yes - you can have a background image

yes - you can overlay text

yes - you can do these as variables.

WATCH OUT - Outlook will need special case coding and does not support transparency (or opaqueness depending on your point of view) for colours, backgrounds, etc.

Cheers

Jo

 

kenmckown
Level 4

For Outlook and transparencies is it best to use overlay images, or is there actual code I can implement for make the BG color transparent?

kenmckown
Level 4

How would I code these into the template to make the editable in the email builder? I want users to be able to add an image and select the transparency level without using code.

Jo_Pitts1
Level 10 - Community Advisor

@kenmckown ,

There is good intel here: https://nation.marketo.com/t5/champion-program-blogs/email-template-quick-start-guide/ba-p/344792

It misses some stuff, but in terms of basics like how to use variables, it'll give you what you need.

Cheers

Jo