Blog


Repurpose your Images for Mobile Email

10.19.2011

Read More Design Emails for Mobile Devices

Get connected with Email on Acid for up-to-date news and information on the subject of email design, development, and testing!

Email Testing RSS Feed Email Test on Twitter Email Preview on Digg Email CSS on Linked In Email Simulator on Stumbled Upon

Email Testing RSS Feed Email Test on Twitter Email Preview on Digg Email CSS on Linked In Email Simulator on Stumbled Upon

By Michelle Klann
July 28, 2011
 
 
 

Stop Yahoo! Mail from rendering your Media Queries

In April 2011, Campaign Monitor published this article which identifies an issue in the way Yahoo! Mail handles media queries. With the help of Brian Sisolak @bsisolak at Trilogy Interactive, we've identified a few more issues with regard to the way Yahoo! Mail handles media query styles intended for mobile devices only.

To make a long story short, each version of Yahoo! ignores your media query declaration along with all of its conditional statements. It then renders each of the styles as if they are outside of the media query to begin with. On top of that, it gets confused with your first declaration which is therefore ignored. So for example, this:

@media only screen and (max-device-width: 480px) {
  #smallScreen {width:100px; padding:2px;}
  .desktop {width:500px; padding:10px;}
}

Will get converted to this:

_filtered #yiv1449593645 {padding:2px;}
#yiv1449593645 .yiv1449593645desktop {width:500px;padding:10px;}
#yiv1449593645

As you can see, Yahoo! converts each of your style names into a name that is unique to your email. They do this in order to keep your styles separate from the ones they use in their interface. So later in the document, it also converts your HTML:

<div class="desktop">Text</div>

Is converted to:

<div class=" yiv1449593645desktop ">Text</div>

Although Yahoo! has really good intentions, I think the problem is occurring because their parsing tool does not take into account media queries and the way they are formatted.

So what's the fix?

Campaign Monitor came up with a sneaky solution to use attribute selectors since they are not support either.  That way your media query and the styles within will not get picked up by Yahoo!

To give an example, if I convert my original query from above, it would look like this:

@media only screen and (max-device-width: 480px) {
  *[id=smallScreen] {width:100px; padding:2px;}
  *[class=desktop] {width:500px; padding:10px;}
}

Another option is to use attribute selectors a little differently wherein you add a "*[class]" before all class declarations and "*[id]" before ID's like this:

@media only screen and (max-device-width: 480px) {
  *[id]#smallScreen {width:100px; padding:2px;}
  *[class].desktop {width:500px; padding:10px;}
}

The bugger about using the examples above is that each element controlled within your media query must contain an HTML attribute (id, class, style, etc). Unfortunatly, universal, type and decendent selectors are out of the question.

So here's one more creative tactic that gives you access to additional selector types:

<style>
  @media only screen and (max-device-width: 480px) {
     body[yahoo] p {color:#00C}
     body[yahoo] .foo {color:#C03}
     body[yahoo] .bar {color:#C03}
   }
</style>
...
<body yahoo="fix">
   <p>test</p>
   <p class="foo">test</p>
   <div class="bar">test</div>
</body>

In this example, I am making up a "yahoo" attribute and placing it in the body tag.  I could have left out the value "fix" but this will help me remember what it's for later on.  Then I am placing "body[yahoo] " before each declaration which now allows me to access universal selectors.

Each of the recommendations above will work in both Yahoo! Classic and Yahoo! Mail.

Comments

I'm a little confused. Doesn't the new Yahoo! Mail mean that this workaround isn't needed anymore?
By James on 08/18/2011

Hey James, yeah it's confusing sorry.

Yahoo Beta has now officially become Yahoo Mail. Yahoo New has been discontinued and Yahoo Classic is difficult to get to. So this fix is still required for Yahoo Mail and Yahoo Classic.
By Michelle Klann on 08/18/2011

Hi I was wondering if you can help solve my problem? I have successfully applied your solution to the HTML except that my 600px wide images are still being scaled to 300px in Yahoo, or being hidden. Are you able to help me understand why? Here's a snippet of my code:

<style type="text/css">
@media only screen and (max-device-width: 480px) {
#table {width:300px !important;}
#cell {width:300px !important;}
#hide {display:none !important;}
#emailHeader {width:300px !important; height:40px !important;}
#borderTop {width:300px !important; height:5px !important; display:none !important;}
#borderBottom {width:300px !important; height:5px !important; display:none !important;}
body[yahoo] #table {width:300px !important;}
body[yahoo] #cell {width:300px !important;}
body[yahoo] #borderTop {display:block !important;}
body[yahoo] #borderBottom {display:block !important;}
}
</style>

The image tag is nestled between tables yet set within the over table/td that has a mobile width of 300pm, much like the Campaign Master example:

http://www.website.com/email/header.gif
By Cellarmasters eCommerce Team on 09/06/2011

Cellarmasters,

Did you add the yahoo="fix" attribute to your body tag?

For example:
<body yahoo="fix">

There is no need to duplicate your styles above (#table and #cell). You must use the body[yahoo] before every declaration in your media query - this is to ensure Yahoo does not render your mobile version:

<style type="text/css">
@media only screen and (max-device-width: 480px) {
body[yahoo] #table {width:300px !important;}
body[yahoo] #cell {width:300px !important;}
body[yahoo] #hide {display:none !important;}
body[yahoo] #emailHeader {width:300px !important; height:40px !important;}
body[yahoo] #borderTop {display:block !important; width:300px !important; height:5px !important;}
body[yahoo] #borderBottom {display:block !important; width:300px !important; height:5px !important;}
}
</style>...
<body yahoo="fix">...

Hope this helps!
By Michelle Klann on 09/06/2011

Yes I have added the <body yahoo="fix"> tag. I have tried using your suggested code. This fixes the Yahoo bug, but the fix then overwrites how it appears in Android native when using Email on Acid to preview. In Android native the image displays at full dimensions 600x80 pixels. So it seems I can please either Yahoo or Android native, but not both. Has anyone else experienced this issue do you know?

Thanks,
Keiron
By Cellarmasters eCommerce Team on 09/06/2011

Keiron,

We have updated our online simulation to reflect this fix, sorry for any confusion! I double checked and confirmed that this fix works correctly on both the iPhone and Android devices.

Cheers,
Miki
By Michelle Klann on 01/09/2012

I've been using this workaround for a while but today I tried removing attribute selector fix and my email still displayed correctly in Yahoo Mail. Perhaps they've fixed this?
By Cameron on 03/21/2012

Share Your Comment

Name:
Email:
Location:
URL:

Comment:

Remember my personal information
Notify me of follow-up comments?

Please enter the word you see in the image below:



Share/Save/Bookmark

If you haven't signed up yet, give our FREE online Email Test a try. Just drop in your code and we will instantly simulate your email in the most popular email clients!

Get connected with Email on Acid for up-to-date news and information on the subject of email design, development, and testing!

Email Testing RSS Feed Email Test on Twitter Email Preview on Digg Email CSS on Linked In Email Simulator on Stumbled Upon

Follow us on Twitter Become a Friend on Facebook Subscribe to our Blog Digg Us! Recommend on StumbleUpon