【问题标题】:Responsive email width in GmailGmail 中的响应式电子邮件宽度
【发布时间】:2018-03-15 13:43:45
【问题描述】:

我有这个电子邮件模板:

<!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 应用上运行,但在桌面版电子邮件内容溢出 &lt;u&gt;&lt;/u&gt;。 如果我从body 标记中删除width:100vw;,桌面工作正常,但移动版本中的内容溢出。我的问题是如何在移动设备上将体宽设置为 100%,在桌面上设置为 600 像素?我尝试了max-width: 600px; 的身体风格,但它不起作用。我也尝试了 100% 而不是 100vw(因为 100 vw 是屏幕宽度),它也不起作用。

【问题讨论】:

    标签: html css gmail html-email responsive


    【解决方案1】:

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

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

    <!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) 中测试现在可以正常工作。

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 不,它没有。只有一半的电子邮件是可见的,其余的会溢出。
      • 我不确定您在做什么,但我针对每个主要电子邮件客户端测试了您在 Litmus 中发布的代码,然后通过将我的版本从 Putsmail 发送到 Gmail 进行了测试。您的版本将事情向右移动。我的版本运行良好,但并未完全以移动 Android 为中心。
      • 是的,我的版本将所有内容都向右移动,我该如何解决?
      • 我通过从 body 标记中删除 width:100vw; 来修复桌面版本。它使 Android 版本的左边距更宽,但表格仍在电子邮件正文中。
      猜你喜欢
      • 1970-01-01
      • 2014-04-03
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2016-09-30
      • 2014-04-20
      相关资源
      最近更新 更多