I have a query that gmail is ignoring "display:none" - what to do? in email html for hide arow or div
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
- Adding a timeout to a render function in ReactJS
For those reaching here with a similar problem relating to mobile/desktop email development in and Gmail - if you're using media queries and showing/hiding content, the embedded css will be unable to overwrite the inline !important declaration. Instead you can use overflow:hidden, like so :
<div class="mobile" style="width:0; overflow:hidden;float:left; display:none"></div>
In your embedded media queries you will naturally undo these styles to reveal the div, and then hide the desktop version of the content.
Unfortunately the height property doesn't work in Gmail, otherwise it would be a better solution, given that this creates a section of whitespace below the visible content equal to the height of the div.
Using
display:none !important;
resolves the issue with gmail but it is then ignored by Outlook 2007 and 2010. Got round this usingdisplay:none; display:none !important;
That way gmail uses one version and Outlook 2007 and 2010 use the other.Though this has already been answered I just thought I'd chip in with a solution that really worked for me in case anyone has this problem in the future. It's really a combination of the above answers and something else that I found online.
The issue that I was having was for Gmail and Outlook. As per the OP, the mobile content I had would not hide in Gmail (Explorer, Firefox and Chrome) or Outlook (2007,2010 & 2013). I solved this by using the following code.
Here's my mobile content:
And here's the CSS:
Fixes for Outlook
So as you can see from the HTML code above, wrapping all the content in these tags;
<!--[if !mso 9]><!--> <!--<![endif]-->
,hides the content for the Outlook versions that I mentioned. For all the other email clients, the
display:none;
works just fine. I also saw that you can also usemso-hide:all
to hide things for Outlook but I thought this was a little easier than placing that code inline.Fixes for Gmail
Now for Gmail, you can see that I created a 'special'
id
calledgmail
which I then applied to a div within the<td>
. I tried COUNTLESS other methods of using things such asoverflow:hidden
inline and all manner of other combinations but this is what worked for me.So in short, wrapping the content in the
<td>
in a<div>
which then contains theoverflow:hidden,width:0
etc then overwriting these styles by giving the div anid
of, in my casegmail
solved the problem for me.Anyway, maybe someone will find this helpful in future!
Thanks for this, very helpful for me.
Try max-height for Gmail this should pick it up. then use max-height:inherit !important; in the CSS this should remove the spacing issue:
Building on Dan S., another example that I use frequently.
If style="display:none" does not work in gmail, put style="display:none !important;" and it works in gmail.