foundation-emails: Media queries fail after inlining
How can we reproduce this bug? I have two different font-size values in my app.scss file. I used the media query exactly as shown in the docs:
/* Main header */
.header {
h1, .tagline {
font-family: Palatino, "Times New Roman", serif;
margin-bottom: 0;
color: $black;
}
h1 {
font-weight: bold;
font-size: 48px;
line-height: 48px;
text-transform: uppercase;
@media only screen and (max-width: #{$global-breakpoint}) {
font-size: 20px;
line-height: 20px;
}
}
.tagline {
font-size: 14px;
line-height: 14px;
}
}
}
When I run npm start, I see the header resize for a smaller viewport:
Wide version:

iPhone 5:

However, when I run npm run build (or npm run zip or npm run litmus), the header does not resize:

When I inspect the h1 in Chrome, I see that the media query styles have not been applied to the tag by the inliner:
Post inlined h1 tag:

Web Inspector in Chrome:

This appears to be true in every mobile client in Litmus as well.
Is it possible that the inliner is not working correctly? I don’t totally understand how it’s supposed to work. Help!
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 16 (4 by maintainers)
If you are missing the media queries in
<head>after running inliner, make sure the placeholder<!-- <style> -->is still there - it will be replaced with the media query styles.I so wish what @timohausmann told would be in the documentation. Would’ve saved me some time figuring out what is happening with my media queries.
In order to use media queries in emails you need to include the
!importantflag as part of the property declaration. However, it’s only necessary for styles that are inlined.Inlined styles take precedence over style/media query tags and you need to override inlined styles for your code to work. It’s a basic order of operations for email developers.
@rafibomb please include this in your Zurb Email Template Docs when using media queries. Also, this issue can be closed. Thanks!
If you have doubts, you can always check css specifity articles. Like this one: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
Also experiencing the same issue in Chrome. Found that using the
!importantissue solved it too. However this should totally not be necessary. On the topic of usingimportant!with media queries. I’m now facing a conundrum of an issue whereby I’d like to display two different styles different screen sizes. Now given:The above will never work correctly because if the screen size is bigger than
480!pxdisplaywill always betablesince it last media instance.As mentioned you shouldn’t have to use
!important, these rules should be respected regardless. What is the correct way of handling multiple media queries without having to use important.@rafibomb - Do you know if there is any movement on this issue?