html - 一种在内联 css 中隐藏 HTML 电子邮件中的表格的方法 - 稍后仅通过媒体查询显示它们

标签 html css email media-queries html-email

我正在使用媒体查询制作我的第一个电子邮件移动模板。到目前为止一切顺利,媒体查询很酷,从现在开始我肯定会在我的网页设计元素中使用它。

但是,我遇到了一个困难;我有一个非常复杂的页眉设计(带有 Facebook 和 youtube Logo 的背景图片,链接到相应的页面),所以它以特定的方式切片。这使得制作移动版本变得不太容易,我想也许我可以用不同的方式修复它:使用两个不同的标题表,一个在大型设备上显示,一个在小型设备上显示。

移动部分没问题,因为它们很好地解释了嵌入式 CSS。

但我似乎无法为其他邮件客户端隐藏完整的表格。我试过 display:none, position:absolute with top and left -9999px, etc...

有人有解决办法吗?这会节省我很多时间。

最佳答案

好吧,我好像自己找到了解决办法:

内联,在普通的非移动版本中要隐藏的表格内的元素上,我放置了以下属性:

line-height:0px;
font-size:0px;
height:0px;
margin:0;
padding:0;

我现在正在用一张表对其进行测试,该表在 td 中包含一个 tr、一个 td 和一个 p。

我几乎将这些属性放在每个元素上:

<table cellpadding="0" cellspacing="0" border="0" align="center" id="hidden">
  <tr class="showmobile" style="line-height:0px;font-size:0px;height:0px;margin:0;padding:0;">
    <td class="showmobile" style="line-height:0px;font-size:0px;height:0px;margin:0;padding:0;">
       <p class="showmobile" style="color:White; line-height:0px;font-size:0px;height:0px;margin:0;padding:0;">Testing this shiznit</p>
    </td>
  </tr>
</table>

我还为这些元素赋予类“showmobile”,我在头部的内部样式表中像这样操作它:

tr[class="showmobile"]
        {
         line-height:125% !important;
         font-size:16px !important;
         height:30px !important;   
        }

td[class="showmobile"]
        {
         line-height:125% !important;
         font-size:16px !important;
         height:30px !important;   
        }

p[class="showmobile"]
        {
         line-height:125% !important;
         font-size:16px !important;
         height:30px !important;   
        }

这种选择类的方式,我从很棒的 html 电子邮件样板 @ http://htmlemailboilerplate.com/ 中获得-> 链接到这篇文章:http://www.campaignmonitor.com/blog/post/3457/media-query-issues-in-yahoo-mail-mobile-email/ -> 基本上,它使 Yahoo mail 播放得很好,并且在不需要时不在媒体查询中应用 CSS。

结论:我在四个平台上测试过它:GMail、Outlook 2010、Lotus Notes(我知道!)和 iPhone 3G。它们都给出了预期的结果,除了 Outlook,它仍然显示 1 像素的线。对于一些智能内容(将文本着色以在背景中显示),这是非常容易隐藏的。

如果我遇到某些邮件客户端的任何问题,我会及时通知你们。

关于html - 一种在内联 css 中隐藏 HTML 电子邮件中的表格的方法 - 稍后仅通过媒体查询显示它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12050675/

相关文章:

javascript - 使用 DataTable 插件获取具有特定类的表的所有 td 值

asp.net - 带有 CSS 的 ImageButton 上的文本

html - 固定最大高度时的 CSS 自动列数

php - DomainKey-Signature 和 DKIM-Signature 之间有什么区别?

html - css 行 : *[class]. testClass{ } 实际上是什么意思?

电子邮件到服务器上的 rss

php - 将 Mysql 回显到表中 - 表示和 DOM

javascript - 单个 MutationObserver 对象可以观察多个目标吗?

jquery - 进出动画有问题

css - html 文件中缺少图像