【问题标题】:HTML email not responsive on Apple MailHTML 电子邮件在 Apple Mail 上没有响应
【发布时间】:2021-01-20 17:53:48
【问题描述】:

我已经构建了一个电子邮件模板,它几乎可以在除 Apple Mail 之外的所有地方完美运行,但我终其一生都无法弄清楚原因。

问题是应该在移动设备上堆叠的一部分列。我通过 Mailchimp 关注 this guide 构建了它们。

这是列的部分:

<table border="0" cellpadding="0" cellspacing="0" id="templateColumns" style="background-color: #ffffff;" width="600">
<tbody>
    <tr>
        <td align="center" class="templateColumnContainer" valign="top" width="50%">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tbody>
                    <tr>
                        <td class="leftColumnContent">
                        <img alt="Placeholder" class="columnImage" src="https://go.frazerconsultants.com/l/43262/2020-08-31/9klwjc/43262/253944/540x400_Placeholder.png" style="font-size: 17; font-family: 'Lato', Helvetica, Arial, sans-serif; line-height: 1.8em; max-width: 280px;" width="280">
                        </td>
                    </tr>
                    <tr>
                        <td class="leftColumnContent" style="color: #404040;" valign="top">
                        <h3 style="font-family: 'Lora', Georgia, serif;">Lorem Ipsum Dolor Sit Amet</h3>

                        <p>&nbsp;</p>

                        <p style="font-size: 17; font-family: 'Lato', Helvetica, Arial, sans-serif; line-height: 1.8em; margin: 0;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>

                        <p>&nbsp;</p>

                        <p><a href="https://frazerconsultants.com/" style="font-size: 17; line-height: 1.8em; font-weight: bold; font-family: 'Lato', Helvetica, Arial, sans-serif; color: #404040; margin: 0; text-decoration: underline;">Read More</a></p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </td>
        <td align="center" class="templateColumnContainer" valign="top" width="50%">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tbody>
                    <tr>
                        <td class="rightColumnContent">
                        <img alt="Placeholder" class="columnImage" src="https://go.frazerconsultants.com/l/43262/2020-08-31/9klwjc/43262/253944/540x400_Placeholder.png" style="font-size: 17; font-family: 'Lato', Helvetica, Arial, sans-serif; line-height: 1.8em; max-width: 280px;" width="280">
                        </td>
                    </tr>
                    <tr>
                        <td class="rightColumnContent" style="color: #404040;" valign="top">
                        <h3 style="font-family: 'Lora', Georgia, serif;">Lorem Ipsum Dolor Sit Amet</h3>

                        <p>&nbsp;</p>

                        <p style="font-size: 17; font-family: 'Lato', Helvetica, Arial, sans-serif; line-height: 1.8em; margin: 0;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>

                        <p>&nbsp;</p>

                        <p><a href="https://frazerconsultants.com/" style="font-size: 17; line-height: 1.8em; font-weight: bold; font-family: 'Lato', Helvetica, Arial, sans-serif; color: #404040; margin: 0; text-decoration: underline;">Read More</a></p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </td>
    </tr>
</tbody>

这是我脑子里的代码,可以让它响应:

@media only screen and (max-width:480px) {

#templateColumns{
  width: 100% !important;
}

.templateColumnContainer{
  display: block !important;
  width: 100% !important;
}

.columnImage{
  height: auto !important;
  width: 100% !important;
  max-width: 580px !important;
}

.leftColumnContent{
  font-size: 17px !important;
  line-height: 125% !important;
}

.rightColumnContent{
  font-size: 17px !important;
  line-height: 125% !important;
}

正如预期的那样,由于媒体查询,它在 Gmail 应用上不起作用,这很好。不可能全部赢。

它在 Outlook 应用上运行良好: Outlook App on iOS/iPhone 11

它不适用于 Apple Mail 应用程序: Apple Mail App on iOS/iPhone 11

基本上,右列不会换行,它只是变得超级瘦,并保持在左列旁边。

我不想发布电子邮件的其余代码,因为我觉得这会使事情变得过于复杂,但如果上下文不够,我可以添加更多内容。

编辑添加:

我确实找到了一种错误的方法,它只能通过在媒体查询部分的 ids/classes 前面添加 [data-outlook-cycle] 来使其在 Outlook 应用程序上响应。至少它使它在 Mail 和 Outlook 中都清晰易读,但理想情况下,我希望电子邮件在 Mail 中也能响应。

【问题讨论】:

    标签: html css email media-queries responsive


    【解决方案1】:

    对我来说这实际上很好用,我将它放入一个完整的文档中并添加了一些常用的基本模板元素,如下所示:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      <meta name="format-detection" content="telephone=no, date=no, address=no, email=no">
      <meta name="x-apple-disable-message-reformatting">
      <title></title>
      <style>
        @media only screen and (max-width:480px) {
    
          #templateColumns{
            width: 100% !important;
          }
    
          .templateColumnContainer{
            display: block !important;
            width: 100% !important;
          }
    
          .columnImage{
            height: auto !important;
            width: 100% !important;
            max-width: 580px !important;
          }
    
          .leftColumnContent{
            font-size: 17px !important;
            line-height: 125% !important;
          }
    
          .rightColumnContent{
            font-size: 17px !important;
            line-height: 125% !important;
          }
        }
      </style>
    </head>
    <body class="body">
      <table border="0" cellpadding="0" cellspacing="0" id="templateColumns" style="background-color: #ffffff;" width="600">
        <tbody>
            <tr>
                <td align="center" class="templateColumnContainer" valign="top" width="50%">
                    <table border="0" cellpadding="10" cellspacing="0" width="100%">
                        <tbody>
                            <tr>
                                <td class="leftColumnContent">
                                <img alt="Placeholder" class="columnImage" src="https://go.frazerconsultants.com/l/43262/2020-08-31/9klwjc/43262/253944/540x400_Placeholder.png" style="font-size: 17; font-family: 'Lato', Helvetica, Arial, sans-serif; line-height: 1.8em; max-width: 280px;" width="280">
                                </td>
                            </tr>
                            <tr>
                                <td class="leftColumnContent" style="color: #404040;" valign="top">
                                <h3 style="font-family: 'Lora', Georgia, serif;">Lorem Ipsum Dolor Sit Amet</h3>
        
                                <p>&nbsp;</p>
        
                                <p style="font-size: 17; font-family: 'Lato', Helvetica, Arial, sans-serif; line-height: 1.8em; margin: 0;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
        
                                <p>&nbsp;</p>
        
                                <p><a href="https://frazerconsultants.com/" style="font-size: 17; line-height: 1.8em; font-weight: bold; font-family: 'Lato', Helvetica, Arial, sans-serif; color: #404040; margin: 0; text-decoration: underline;">Read More</a></p>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
                <td align="center" class="templateColumnContainer" valign="top" width="50%">
                    <table border="0" cellpadding="10" cellspacing="0" width="100%">
                        <tbody>
                            <tr>
                                <td class="rightColumnContent">
                                <img alt="Placeholder" class="columnImage" src="https://go.frazerconsultants.com/l/43262/2020-08-31/9klwjc/43262/253944/540x400_Placeholder.png" style="font-size: 17; font-family: 'Lato', Helvetica, Arial, sans-serif; line-height: 1.8em; max-width: 280px;" width="280">
                                </td>
                            </tr>
                            <tr>
                                <td class="rightColumnContent" style="color: #404040;" valign="top">
                                <h3 style="font-family: 'Lora', Georgia, serif;">Lorem Ipsum Dolor Sit Amet</h3>
        
                                <p>&nbsp;</p>
        
                                <p style="font-size: 17; font-family: 'Lato', Helvetica, Arial, sans-serif; line-height: 1.8em; margin: 0;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
        
                                <p>&nbsp;</p>
        
                                <p><a href="https://frazerconsultants.com/" style="font-size: 17; line-height: 1.8em; font-weight: bold; font-family: 'Lato', Helvetica, Arial, sans-serif; color: #404040; margin: 0; text-decoration: underline;">Read More</a></p>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
      </table>
    </body>
    </html>
    

    对我来说,这在 Gmail 应用程序(只要是 Gmail 地址,对于非 Gmail 地址不会应用媒体查询)、Outlook 应用程序和本机 iOS 邮件应用程序中叠加。

    问题可能出在您文档中的其他地方吗?

    【讨论】:

    • 谢谢妮可!由于您的评论,我在其他地方做了一些消除过程,发现问题出在 doctype 声明: -//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> w3.org/1999/xhtml"> 更新后它开始运行得很漂亮!