【问题标题】:Gmail font-size increase in HTML Email templateHTML 电子邮件模板中的 Gmail 字体大小增加
【发布时间】:2022-01-01 23:40:20
【问题描述】:

我对 Gmail 中的 html 电子邮件模板有疑问。到目前为止,在所有其他呈现的浏览器/邮件客户端中,它的呈现都很好,但我在 Gmail Android 应用程序上发现了一个问题(在三星 Galaxy S9+ 上测试)。

Screenshot of rendered mail in Gmail App

正如您在图片中看到的那样,图片旁边的大标题由于溢出而被剪切 - 我没有解决方法来防止这种情况发生。如前所述,到目前为止,这在其他(移动)邮件客户端上还没有发生过。

在 Stack 和其他资源上发现,Gmail 应用程序可以增加字体大小 - 尝试了我迄今为止看到的以下提示,但都没有任何积极效果:

  • !important 直接在和/或与 .listing-title 一起使用
  • 字体大小为 pt 而不是 px(带和不带 !important)
  • spacer.gif 作为顶行(在左侧创建巨大的空白空间)
  • 空白:nowrap;不能使用,因为通常这些标题大于一行,并且当被溢出切断时看起来很奇怪:隐藏
  • 带有“u + .gmail”的特殊类

即使我改变图像和文本容器的高度 - 这当然会影响所有邮件客户端......

注意:我不允许做大的设计更改,所以它需要左侧是img,右侧是这些文本。

是否有人对如何防止这种切断有进一步的建议? 提前谢谢!

  .ReadMsgBody {
          width: 100%;
        }
        .ExternalClass {
          width: 100%;
        }
        span.yshortcuts {
          color: #000;
          background-color: none;
          border: none;
        }
        span.yshortcuts:hover,
        span.yshortcuts:active,
        span.yshortcuts:focus {
          color: #000;
          background-color: none;
          border: none;
        }
        html,
        table {
          font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", arial;
        }
        .main-tbody * {
          margin: 0;
          padding: 0;
        }
        .padding {
          width: 50px;
        }
        .copyright {
          width: 500px;
        }
        .location-row {
          display: block !important;
        }
        .button-padding {
          display: none !important;
        }
        
        @media screen and (max-width:620px) {
          .location-row {
            display: none !important;
          }
          .main-table {
            width: 320px !important;
          }
          .inner-table {
            width: 320px !important;
          }
          .image-listing {
            width: 80px !important;
            height: 60px !important;
            max-width: 80px !important;
            max-height: 60px !important;
          }
          .image-container {
            width: 80px !important;
            height: 60px !important;
          }
          .listing-title {
            font-size: 14px !important;
            line-height: 18px !important;
            height: 35px !important;
          }
          .listing-price {
            font-size: 12px !important;
            height: 14px !important;
          }
          .button-padding {
            display: block !important;
          }
          .copyright {
            width: 320px !important;
          }
        }
        
        a[x-apple-data-detectors],
        .x-gmail-data-detectors,
        .x-gmail-data-detectors *,
        .aBn,
        u+#body a,
        #MessageViewBody a {
          color: inherit;
          text-decoration: none;
          font-size: inherit;
          font-family: inherit;
          font-weight: inherit;
          line-height: inherit;
        }
 <body id="body" style="font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, 'Helvetica Neue', sans-serif; margin:0; min-width:320px;">
      <table class="main-table" border="0" cellpadding="0" cellspacing="0" align="center" style="text-align: center; background: #f5f5f5; margin-inline-start: auto; margin-inline-end: auto;" width="600">
        <tbody class="main-tbody">
          <!-- Header -->
          <tr align="center" style="margin: 0 auto; text-align: center;">
            <td colspan="3">
              <table class="inner-table" border="0" cellpadding="0" cellspacing="0" align="center" width="500" style="margin: 0 auto; text-align: center;">
                <tbody align="center">
                  <tr>
                    <td colspan="3" height="40" style="height: 40px;">
                      <p style="margin: 0;"></p>
                    </td>
                  </tr>
                  <tr style="height: 40px; width: 100%;" align="center">
                    <td colspan="3" class="desktop-logo" width="500">
                      <img height="48" width="128" style="display: inline-block; vertical-align: middle" alt="Logo" src="https://via.placeholder.com/128x48.png?text=logo">
                    </td>
                  </tr>
                  <tr>
                    <td colspan="3" height="30" style="height: 30px;">
                      <p style="margin: 0;"></p>
                    </td>
                  </tr>
                </tbody>
              </table>
            </td>
          </tr>
          <!-- Header -->
          <tr>
            <td class="padding" width="50"></td>
            <td>
             
              <!-- Listing -->
              <table class="inner-table" border="0" cellpadding="0" cellspacing="0" align="center" style="background-color: #ffffff;" width="500">
                <tbody>
                <tr class="list-container" style="width: 100%; max-height:140px;">
                  <td width="10"></td>
                  <td class="image-container" colspan="1" width="160" height="140" style="max-height:140px;">
                    <a href="">
                      <img class="image-listing" src="https://via.placeholder.com/160x120.jpeg?text=image" alt="" style="display: block; width: 100%; height: 100%; max-height: 120px;max-width: 100%; object-fit: cover" width="160" height="120">
                    </a>
                  </td>
                  <td width="10"></td>
                  <td class="text-container" colspan="2">
                    <table border="0" cellpadding="0" cellspacing="0" align="left" width="100%" style="width: 100%;">
                      <tbody>
                      <tr>
                        <td class="padding-top-inner-table" height="10" style="height: 10px;">
                          <p style="margin: 0;"></p>
                        </td>
                      </tr>
                      <tr>
                        <td>
                          <a href="" style="width: 500px">
                            <table border="0" cellpadding="0" cellspacing="0" align="left" width="500" style="width: 100%; text-align: left; color: #212338;">
                              <tbody>
                              <tr class="location-row">
                                <td style="width:100%; font-size: 12px; font-weight: 400;display: block; height:16px;" height="16">
                                  <a href="" style="overflow: hidden;  width:100%;height: 16px; margin: 0;text-decoration: none;color: #232f3f; display: block">
                                    A small title
                                  </a>
                                </td>
                              </tr>
                              <tr>
                                <td class="location-row" height="10" style="height: 10px;">
                                  <p style="margin: 0;"></p>
                                </td>
                              </tr>
                              <tr>
                                <td class="listing-title" style="font-size: 16px; height:42px; font-weight: 400;display: block" height="42">
                                  <a class="listing-title" href="" style="overflow: hidden; height: 42px; margin: 0;color: #232f3f;display: block; text-decoration: none; font-weight:bold; font-size: 16px;">
                                    The very main big title which makes problems
                                  </a>
                                </td>
                              </tr>
                              <tr class="location-row" height="27" style="height: 27px;">
                                <p style="margin: 0;"></p>
                              </tr>
                              <tr height="8" style="height: 8px;">
                                <p style="margin: 0;"></p>
                              </tr>
                              <tr height="19" style="height: 19px;">
                                <td class="listing-price" height="18" style="height:18px; margin: 0;font-weight: normal; font-size:14px; text-align: left; text-decoration: none;">
                                     Tag 1 |    Tag 2    | € price  
                                </td>
                              </tr>
                              </tbody>
                            </table>
                          </a>
                        </td>
                        <td width="15" style="width: 15px;">
                          <p style="margin: 0;"></p>
                        </td>
                      </tr>
                      <tr>
                        <td colspan="3" height="8" style="height: 8px;">
                          <p style="margin: 0;"></p>
                        </td>
                      </tr>
                      </tbody>
                    </table>
                  </td>
                </tr>
                <tr>
                  <td colspan="5" height="10" style="height: 10px; background: #f5f5f5;">
                    <p style="margin: 0;"></p>
                  </td>
                </tr>
                </tbody>
              </table>

              <!-- Listing -->

            </td>
            <td class="padding"></td>
          </tr>

        </tbody>
      </table> 

【问题讨论】:

  • 您是使用 Gmail 地址(或 Gmail 化的地址)还是第三方电子邮件地址(如 Outlook.com 或 Yahoo)进行测试?这会极大地影响对 CSS 的支持。 (详情请参阅hteumeuleu.com/2019/…。)
  • 我正在使用@gmail.com 地址进行测试,已经阅读了有关 GANGA 的信息。您在该页面上的图形很好。

标签: html css email gmail


【解决方案1】:

我似乎无法在 Android 版 Gmail 中重现您的屏幕截图中的问题。我的猜测是您的代码中还有其他内容与 Gmail 的呈现冲突。我看到的一件事是您的代码中到处都缺少&lt;td&gt;s。例如这里:

<tr class="location-row" height="27" style="height: 27px;">
    <p style="margin: 0;"></p>
</tr>

这应该是:

<tr class="location-row" height="27" style="height: 27px;">
    <td><p style="margin: 0;"></p></td>
</tr>

您的代码中还有两个 &lt;body&gt; 元素。

作为 Gmail 故障排除的一般规则,我会:

  • 确保您的&lt;style&gt; 标签位于电子邮件的&lt;head&gt; 内。 Gmail 不支持 &lt;body&gt; 中的 &lt;style&gt;。
  • 确保您的电子邮件在使用和不使用&lt;style&gt; 标记时都能正确呈现。使用非 Gmail 帐户的 Gmail 移动网络邮件和 Gmail 应用不支持&lt;style&gt; 标签。
  • 确保您的 HTML 总重量不超过 102 Kb。 Gmail clips email at 102 Kb 和 limits &lt;style&gt; to 16 Kb。
  • 使用不会改变您的 HTML 的中立服务来发送您的测试(例如 Putsmail 或 Parcel)。

这是我写的关于 troubleshooting Gmail’s responsive design support 的旧帖子。

如果这仍然没有帮助,请随时分享您为触发该错误而发送的整个代码。

【讨论】:

  • 谢谢 - 我更正了丢失的 。双 只是这里的情况,显然我在代码中复制了两次。我在不同邮件应用程序中的真实智能手机上测试了代码,我猜现在这是由于定义的图像高度而发生的,但需要进一步测试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-26
  • 2023-03-15
  • 1970-01-01
  • 2021-03-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多