【发布时间】:2018-09-16 23:32:48
【问题描述】:
我正在尝试为电子邮件编写一些 HTML/CSS,但无法响应地显示和隐藏内容。我有一张大桌子,有两张嵌套的桌子。每个嵌套表格都是根据屏幕大小隐藏或显示的页脚。这是代码
<style>
@media all and (max-width: 768px) {
table[table-view=desktop] {
display: none !important;
}
table[table-view=mobile] {
display: block;
}
}
@media all and (min-width: 769px) {
table[table-view=mobile] {
display: none !important;
}
table[table-view=desktop] {
display: block;
}
}
</style>
<some other stuff here>
<table class="module mobile-view" table-view="mobile" border="0" cellpadding="0" cellspacing="0" data-type="code" role="module" style="table-layout: fixed;">
...
</table>
<table class="module desktop-view" table-view="desktop" role="module" data-type="code" border="0" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;">
...
</table>
在 Gmail 中查看此内容时,两个页脚都会出现。使用邮件构建工具(SendGrid)中的预览工具时,效果很好。
我尝试在媒体查询中选择 mobile-view 和 desktop-view 类,但没有奏效 - 所以我尝试将属性放入 HTML。
我做错了什么?
【问题讨论】:
-
Gmail 对空格真的很挑剔。删除
min-width:769px之间的空格并正确使用类,例如:table.desktop-view{display: block;}如果您无法工作,请告诉我,我将在其中放入一个工作示例。 -
@Syfer 我试过你的建议无济于事!如果您能提供一个工作示例,我将不胜感激。
标签: css email gmail html-email sendgrid