简体   繁体   English

HTML电子邮件-GMAIL显示块无法正常工作

[英]HTML email - GMAIL display block doesn't work properly

I've been creating a HTML email campaign that has to be responsive. 我一直在创建一个必须响应的HTML电子邮件活动。 On desktop, the email has 2 columns, but on mobile it has to display them as 1 column. 在台式机上,电子邮件有2列,但在移动设备上,电子邮件必须显示为1列。

This is working in other clients as expected, but in Gmail, the column (td) doesn't go full width (image attached). 这在其他客户端上可以正常使用,但是在Gmail中,列(td)不能全角显示(已附加图像)。

So the structure is something like this: 所以结构是这样的:

<table class="w640">
  <tr>
    <td class="w640">COLUMN 1</td>
    <td class="w640">COLUMN 2</td>
 </tr>
</table>

Then the CSS is: 那么CSS是:

@media only screen and (max-width: 639px) {
 table[class=w640], 
 td[class=w640] { width:90% !important; display:block !important; }
}

This is what is happening in Gmail. 这就是Gmail中发生的事情。 The 2 columns are not going 100% width: 2列的宽度不是100%: 在此处输入图片说明

I think your problem might be that you didn't assign a width to your table. 我认为您的问题可能是您没有为表格分配宽度。 You can either give this a static (px) or a flexible (%) width. 您可以为此设置静态(px)或灵活(%)的宽度。

Display block on td & tr should do the job for you then. 然后,td&tr上的Display block应该会为您完成这项工作。 hope that helps you out a bit. 希望对您有所帮助。

 @media only screen and (max-width: 639px) { tr td { display: block; /*neccasary*/ } } td { background: blue; } table { text-align: center; width: 90%; background: red; margin: 0 auto; } div { background: yellow; width: 400px; /*neccasary if table is given a percentage*/ height: 400px; } 
 <div> <table class="w640"> <tr> <td class="w640">COLUMN 1</td> <td class="w640">COLUMN 2</td> </tr> </table> </div> 

I have what seems to be exactly the same problem and was looking for a solution. 我有似乎完全相同的问题,正在寻找解决方案。 I already had a width specified for the table, so it wasn't that. 我已经为表格指定了宽度,所以不是。

In the end I used <th> 's instead of the <td> , and now it works! 最后,我用<th>代替了<td> ,现在可以了!

Hope this helps someone. 希望这对某人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM