Gmail 中的响应式电子邮件宽度

Responsive email width in Gmail

我有这个电子邮件模板:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>title</title>
    <style type="text/css">
    img { max-width: 600px;  -ms-interpolation-mode: bicubic;}
    .ReadMsgBody { width: 100%; }
    .ExternalClass {width:100%;}
    .backgroundTable {margin:0 auto; padding:0; width:100%;!important;}
    body {
      width: 100%;
      height: 100%;
      direction: rtl;
    }
    .force-full-width {
      width: 100% !important;
    }
    </style>
    <style type="text/css" media="only screen and (max-width: 599px)">
      @media only screen and (max-width: 599px) {
        table[class*="w320"] {
          width: 320px !important;
        }
      }
    </style>
  </head>
  <body dir="rtl" class="body" style="width:100vw; padding:0; margin:0; display:block; background:#ffffff; -webkit-text-size-adjust:none" bgcolor="#ffffff">
  <table align="center" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td align="center" valign="top" style="background-color:#ffffff" width="100%">
      <center>
        <table cellspacing="0" cellpadding="0" width="600" class="w320">
          <tr>
            <td align="center" valign="top">
              <table class="force-full-width"  width="100%" cellspacing="0" cellpadding="20" bgcolor="#ef6900">
                <tr>
                  <td style="background-color:#ef6900; color:#ffffff; font-size: 14px; text-align: center;">
                    Some text
                  </td>
                </tr>
              </table>
              <!-- more tables -->
            </td>
          </tr>
        </table>
      </center>
      </td>
    </tr>
  </table>
  </body>
</html>

它确实适用于 Android 中的 Gmail 应用程序,但在桌面版中电子邮件内容会溢出 <u></u>。 如果我从 body 标签中删除 width:100vw;,桌面版工作正常但内容在移动版中溢出。我的问题是如何使 body 宽度在移动设备上为 100%,在桌面设备上为 600px?我尝试了 max-width: 600px; 的 body 样式,但它不起作用。我也试过 100% 而不是 100vw(因为 100vw 是屏幕宽度),它也不起作用。

如果您从正文标签中删除 width:100vw;,您的电子邮件将正常工作。

我做了一些修改,希望这是你想要的结果。我做了以下事情:

  • 从正文中删除了width:100vw
  • 在 body 标签上添加了您正在使用的 class 正文,并定义了正文 CSS。
  • 更改了媒体查询(删除了 space)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
 <title>title</title>
 <style type="text/css">img { max-width: 600px;  -ms-interpolation-mode: bicubic;}
    .ReadMsgBody { width: 100%; }
    .ExternalClass {width:100%;}
    .backgroundTable {margin:0 auto; padding:0; width:100%;!important;}
    body, .body {
      width: 100%;
      height: 100%;
      direction: rtl;
    }
    .force-full-width {
      width: 100% !important;
    }
 </style>
 <style media="only screen and (max-width: 599px)" type="text/css">@media only screen and (max-width:599px) {
        table.w320 {
          width: 320px !important;
        }
      }
 </style>
</head>
<body bgcolor="#ffffff" class="body" dir="ltr" style="padding:0; margin:0; display:block; background:#ffffff; -webkit-text-size-adjust:none">
<table align="center" cellpadding="0" cellspacing="0" width="100%">
 <tbody>
  <tr>
   <td align="center" style="background-color:#ffffff" valign="top" width="100%">
   <center>
   <table cellpadding="0" cellspacing="0" class="w320" width="600">
    <tbody>
     <tr>
      <td align="center" valign="top">
      <table bgcolor="#ef6900" cellpadding="20" cellspacing="0" class="force-full-width" width="100%">
       <tbody>
        <tr>
         <td style="background-color:#ef6900; color:#ffffff; font-size: 14px; text-align: center;">Some text</td>
        </tr>
       </tbody>
      </table>
      <!-- more tables --></td>
     </tr>
    </tbody>
   </table>
   </center>
   </td>
  </tr>
 </tbody>
</table>
</body>
</html>

以上代码在 Outlook 2017 和 Gmail 应用程序 (v8.2.11) 中测试,现在可以正常工作。

如果您有任何问题,请告诉我。