【问题标题】:outlook 2007 - 2019 css issue for Email templatesOutlook 2007 - 2019 电子邮件模板的 css 问题
【发布时间】:2021-11-01 06:09:33
【问题描述】:

我正在设置 HTML 模板,其父正文宽度为 600 像素,但在 Outlook 2007 - 2019 中,已占用全部可用宽度。

图像在 Outlook 版本中占用 100% 的宽度,但它应该只占用 600 像素的宽度。对于其他人来说,它工作正常。

预期图片:

错误图片:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>test</title>
    <link
      href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900"
      rel="stylesheet"
      type="text/css"
    />
    <style type="text/css">
      .main-wrapper .email_content p {
        padding-left: 10px;
      }
      img {
        max-width: 600px;
        outline: none;
        text-decoration: none;
        -ms-interpolation-mode: bicubic;
      }
      a img {
        border: none;
      }
      table {
        border-collapse: collapse !important;
      }
      #outlook a {
        padding: 0;
      }
      table td {
        border-collapse: collapse;
      }
    </style>
  </head>
  <body>
    <table align="center" width="100%" class="main-wrapper">
      <tr>
        <td style="background-color: #dddddd">
          <table
            cellpadding="0"
            cellspacing="0"
            border="0"
            width="100%"
            style="font-family: Roboto, Arial; font-size: 13px"
          >
            <tr bgcolor="#eeeeee">
              <td align="center">
                <table cellpadding="0" cellspacing="0" width="600" border="0">
                  <tr>
                    <!-- <td style="padding: 20px 20px 20px 20px;"> -->
                    <td style="padding: 20px 0px 20px 0px">
                      <table
                        cellspacing="0"
                        cellpadding="0"
                        border="0"
                        width="100%"
                        style="box-shadow: 0px 0px 4px 2px #e0e0e0"
                      >
                        <tr bgcolor="#ffffff">
                          <!-- <td style="padding: 25px; border: 1px solid #e2e2e2; color: #666666;"> -->
                          <td style="color: #666666; padding: 0">
                            <table
                              cellpadding="0"
                              cellspacing="0"
                              border="0"
                              width="100%"
                            >
                              <tr>
                                <td
                                  class="email_content"
                                  style="
                                    padding-bottom: 15px;
                                    background-color: #fafafa;
                                  "
                                >
                                  <div
                                    style="
                                      padding: 5px;
                                      border-radius: 4px 4px 0px 0px;
                                      background-color: #fdaf74;
                                    "
                                  ></div>
                                  <!-- <img src="https://res.cloudinary.com/dyyjph6kx/image/upload/f_auto/webui/eng/xoxoday-logo.svg" height="40"> -->
                                  <!-- <img src=https://xoxoday-dropbox-uat.s3.ap-southeast-1.amazonaws.com/image/clients/10178600000000000/platform_setting/First_American_Logo_0.jpg height="40"> -->
                                  <img style="padding : 20px 0 0 25px;"
                                  src=https://xoxoday-dropbox-uat.s3.ap-southeast-1.amazonaws.com/image/clients/10178600000000000/platform_setting/First_American_Logo_0.jpg
                                  height="40">
                                </td>
                              </tr>
                              <tr>
                                <table style="margin: 0 7px">
                                  <table
                                    align="center"
                                    width="100%"
                                    class="main-wrapper"
                                    style="border-bottom: 1px solid #eee"
                                  >
                                    <tr>
                                      <td>
                                        <table
                                          cellpadding="0"
                                          cellspacing="0"
                                          border="0"
                                          width="100%"
                                          style="font-family: Roboto, Arial"
                                        >
                                          <tr bgcolor="#F2F2F2">
                                            <td align="center">
                                              <table
                                                cellpadding="0"
                                                cellspacing="0"
                                                width="600"
                                                border="0"
                                              >
                                                <tr>
                                                  <td>
                                                    <table
                                                      cellspacing="0"
                                                      cellpadding="0"
                                                      border="0"
                                                      width="100%"
                                                    >
                                                      <tr bgcolor="#ffffff">
                                                        <td>
                                                          <table
                                                            cellpadding="0"
                                                            cellspacing="0"
                                                            border="0"
                                                            width="100%"
                                                          >
                                                            <tr>
                                                              <td
                                                                style="
                                                                  text-align: left;
                                                                  font-size: 16px;
                                                                  padding: 6px 0
                                                                    10px 18px;
                                                                "
                                                              >
                                                                <p
                                                                  style="
                                                                    color: #1a1a1a;
                                                                  "
                                                                >
                                                                  Hi Sheetal
                                                                  Chourasiya,
                                                                </p>
                                                                <p
                                                                  style="
                                                                    color: #505050;
                                                                  "
                                                                >
                                                                  You have
                                                                  received Plum
                                                                  E-Gift Card.
                                                                  Congratulations!
                                                                </p>
                                                              </td>
                                                            </tr>
                                                            <tr>
                                                              <td
                                                                align="center"
                                                              >
                                                                <img
                                                                  src="http://xoxoday-testing.s3.amazonaws.com/store/template/belatedBirthday/belated-happy-birthday-3.jpg"
                                                                  style="
                                                                    margin: 0;
                                                                    border: 0;
                                                                    padding: 0;
                                                                    display: block;
                                                                  "
                                                                  width="600px"
                                                                  height="300px"
                                                                  alt="Image"
                                                                />
                                                              </td>
                                                            </tr>

                                                            <tr>
                                                              <td
                                                                style="
                                                                  padding: 24px
                                                                    60px 0;
                                                                "
                                                              >
                                                                <table
                                                                  cellpadding="0"
                                                                  cellspacing="0"
                                                                  border="0"
                                                                  width="100%"
                                                                  style="
                                                                    text-align: left;
                                                                    font-size: 14px;
                                                                    background-color: #fafafa;
                                                                    border-radius: 6px;
                                                                    margin-bottom: 30px;
                                                                  "
                                                                >
                                                                  <tr>
                                                                    <th
                                                                      style="
                                                                        padding: 24px
                                                                          0 10px
                                                                          24px;
                                                                        text-align: left;
                                                                        font-size: 16px;
                                                                        color: #505050;
                                                                      "
                                                                    >
                                                                      Plum
                                                                      E-Gift
                                                                      Card
                                                                    </th>
                                                                    <td
                                                                      style="
                                                                        text-align: right;
                                                                        padding-right: 20x;
                                                                      "
                                                                    >
                                                                      <a
                                                                        href="https://docs.xoxoday.com/docs/getting-started-1"
                                                                        target="_blank"
                                                                        style="
                                                                          color: #c7417b;
                                                                          text-decoration: none;
                                                                          display: none;
                                                                        "
                                                                        >What is
                                                                        Plum?</a
                                                                      >
                                                                    </td>
                                                                  </tr>
                                                                  <tr
                                                                    style="
                                                                      box-shadow: 0px -1px
                                                                        0 0 #eaeaea;
                                                                    "
                                                                  >
                                                                    <td
                                                                      style="
                                                                        padding: 20px
                                                                          0 20px
                                                                          24px;
                                                                      "
                                                                    >
                                                                      <table
                                                                        cellpadding="0"
                                                                        cellspacing="0"
                                                                        border="0"
                                                                      >
                                                                        <tr>
                                                                          <td>
                                                                            <span
                                                                              style="
                                                                                color: #909090;
                                                                                font-size: 16px;
                                                                                margin: 0;
                                                                              "
                                                                              >Gift
                                                                              Card
                                                                              Code</span
                                                                            >
                                                                          </td>
                                                                        </tr>
                                                                        <tr>
                                                                          <td>
                                                                            <span
                                                                              style="
                                                                                color: #505050;
                                                                                font-size: 20px;
                                                                                margin: 6px
                                                                                  0
                                                                                  0
                                                                                  0;
                                                                                font-weight: 500;
                                                                                letter-spacing: 0.025rem;
                                                                              "
                                                                              >77m43dddb46b</span
                                                                            >
                                                                          </td>
                                                                        </tr>
                                                                      </table>
                                                                    </td>
                                                                  </tr>
                                                                </table>
                                                              </td>
                                                            </tr>
                                                          </table>
                                                        </td>
                                                      </tr>
                                                    </table>
                                                  </td>
                                                </tr>
                                              </table>
                                            </td>
                                          </tr>
                                        </table>
                                      </td>
                                    </tr>
                                  </table>
                                </table>
                              </tr>
                            </table>
                          </td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </body>
</html>

【问题讨论】:

标签: html css outlook-2010 outlook-2007 email-templates


【解决方案1】:

改变这一行:

<table align="center" style="width: 100%" class="main-wrapper">

收件人:

<table align="center" style="width: >100%" class="main-wrapper">

(>100% 是小于 100 的数字,例如 90)

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:

像 div 或 p 这样的块级元素的初始宽度是 auto。

使用 [ width: auto ] 撤消明确指定的宽度。

如果您指定 [width:100%],则元素的总宽度将是其包含块的 100% 加上任何水平边距、内边距和边框。

  • width: auto; 会在从边距、内边距或边框添加额外空间时尽可能努力地保持元素与其父容器的宽度相同。

  • width: 100%; 将使元素与父容器一样宽。额外的间距将添加到元素的大小,而不考虑父元素。这通常会导致问题。

查看下面的图片链接以获取更多信息。

HTML Width - by Shashank

【讨论】:

  • 他的代码中已经有 600px 宽度的表格。所有外部表都是 100% 宽度。它的图像。导致问题的是他的图像定义
【解决方案3】:

您的生日代码图像上有 px 值。我已将其删除并通过在线清洁器稍微更新了您的代码。我是 Dreamweaver 用户,您的代码对我不起作用。如果下面的代码有问题,只需更改您的生日图像 (belated-happy-birthday-3.jpg) 的宽度值并分配不带像素的宽度值。

试试这个代码,看看它是否适合你。

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>test</title>
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900" rel="stylesheet" type="text/css">
  <style type="text/css">
  .main-wrapper .email_content p {
        padding-left: 10px;
  }
  img {
        max-width: 600px;
        outline: none;
        text-decoration: none;
        -ms-interpolation-mode: bicubic;
  }
  a img {
        border: none;
  }
  table {
        border-collapse: collapse !important;
  }
  #outlook a {
        padding: 0;
  }
  table td {
        border-collapse: collapse;
  }
  </style>
</head>
<body>
  <table align="center" width="100%" class="main-wrapper">
    <tr>
      <td style="background-color: #dddddd">
        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="font-family: Roboto, Arial; font-size: 13px">
          <tr bgcolor="#EEEEEE">
            <td align="center">
              <table cellpadding="0" cellspacing="0" width="600" border="0">
                <tr>
                  <!-- <td style="padding: 20px 20px 20px 20px;"> -->
                  <td style="padding: 20px 0px 20px 0px">
                    <table cellspacing="0" cellpadding="0" border="0" width="100%" style="box-shadow: 0px 0px 4px 2px #e0e0e0">
                      <tr bgcolor="#FFFFFF">
                        <!-- <td style="padding: 25px; border: 1px solid #e2e2e2; color: #666666;"> -->
                        <td style="color: #666666; padding: 0">
                          <table cellpadding="0" cellspacing="0" border="0" width="100%">
                            <tr>
                              <td class="email_content" style="padding-bottom: 15px; background-color: #fafafa;">
                                <div style="padding: 5px; border-radius: 4px 4px 0px 0px; background-color: #fdaf74;"></div><!-- <img src="https://res.cloudinary.com/dyyjph6kx/image/upload/f_auto/webui/eng/xoxoday-logo.svg" height="40"> --><!-- <img src=https://xoxoday-dropbox-uat.s3.ap-southeast-1.amazonaws.com/image/clients/10178600000000000/platform_setting/First_American_Logo_0.jpg height="40"> --><img src="https://xoxoday-dropbox-uat.s3.ap-southeast-1.amazonaws.com/image/clients/10178600000000000/platform_setting/First_American_Logo_0.jpg" alt="First_American_Logo_0" width="142" height="40" style="padding : 20px 0 0 25px;">
                              </td>
                            </tr>
                            <tr>
                              <td></td>
                            </tr>
                            <tr>
                              <td>
                                <table cellpadding="0" cellspacing="0" border="0" width="100%" style="font-family: Roboto, Arial">
                                  <tr bgcolor="#F2F2F2">
                                    <td align="center">
                                      <table cellpadding="0" cellspacing="0" width="600" border="0">
                                        <tr>
                                          <td>
                                            <table cellspacing="0" cellpadding="0" border="0" width="100%">
                                              <tr bgcolor="#FFFFFF">
                                                <td>
                                                  <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                                    <tr>
                                                      <td style="text-align: left; font-size: 16px; padding: 6px 0 10px 18px;">
                                                        <p style="color: #1a1a1a;">Hi Sheetal Chourasiya,</p>
                                                        <p style="color: #505050;">You have received Plum E-Gift Card. Congratulations!</p>
                                                      </td>
                                                    </tr>
                                                    <tr>
                                                      <td align="center"><img src="http://xoxoday-testing.s3.amazonaws.com/store/template/belatedBirthday/belated-happy-birthday-3.jpg" style="margin: 0; border: 0; padding: 0; display: block;" width="600" height="300" alt="Image"></td>
                                                    </tr>
                                                    <tr>
                                                      <td style="padding: 24px 60px 0;">
                                                        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="text-align: left; font-size: 14px; background-color: #fafafa; border-radius: 6px; margin-bottom: 30px;">
                                                          <tr>
                                                            <th style="padding: 24px 0 10px 24px; text-align: left; font-size: 16px; color: #505050;">Plum E-Gift Card</th>
                                                            <td style="text-align: right; padding-right: 20x;">
                                                              <a href="https://docs.xoxoday.com/docs/getting-started-1" target="_blank" style="color: #c7417b; text-decoration: none; display: none;">What is Plum?</a>
                                                            </td>
                                                          </tr>
                                                          <tr style="box-shadow: 0px -1px 0 0 #eaeaea;">
                                                            <td style="padding: 20px 0 20px 24px;">
                                                              <table cellpadding="0" cellspacing="0" border="0">
                                                                <tr>
                                                                  <td><span style="color: #909090; font-size: 16px; margin: 0;">Gift Card Code</span></td>
                                                                </tr>
                                                                <tr>
                                                                  <td><span style="color: #505050; font-size: 20px; margin: 6px 0 0 0; font-weight: 500; letter-spacing: 0.025rem;">77m43dddb46b</span></td>
                                                                </tr>
                                                              </table>
                                                            </td>
                                                          </tr>
                                                        </table>
                                                      </td>
                                                    </tr>
                                                  </table>
                                                </td>
                                              </tr>
                                            </table>
                                          </td>
                                        </tr>
                                      </table>
                                    </td>
                                  </tr>
                                </table>
                              </td>
                            </tr>
                          </table>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>

【讨论】:

    【解决方案4】:

    问题出在下面一行:

        <table align="center" style="width: 100%" class="main-wrapper">
    

    当你使用style = "width: 100%"时,你是说你希望表格的宽度是整个浏览器的宽度;父容器的宽度和边距相结合。

    有几种方法可以解决此问题:

    第一种方式是使用width: auto

        <table align="center" style="width: auto" class="main-wrapper">
    

    另一种手动设置像素的方法:

        <table align="center" style="width: 600px" class="main-wrapper">
    

    或者,您可以将样式作为一个整体去掉,使其自动适应父宽度:

        <table align="center" class="main-wrapper">
    

    所有这三种方法都会产生相同的结果。

    【讨论】:

    • 他的代码中已经有 600px 宽度的表格。所有外部表都是 100% 宽度。它的图像。导致问题的是他的图像定义