html - CSS 从 Outlook Online 中的单个 div 元素中剥离

标签 html css email html-email

我正在尝试创建一个在在线版 outlook 和 gmail 中都能正确显示的电子邮件。我似乎让它在 gmail 中运行良好,但在 outlook 中遇到了一个奇怪的问题。我有两个相同的元素,里面有一个图像。当我在 outlook 中查看第一个时,它会删除内联样式属性的整个元素。然后它在第二个上使用相同的代码工作得很好。 (见截图)我知道电子邮件客户端之间存在奇怪的不一致,但我不确定这里发生了什么。如果有人有任何想法,请告诉我。

我环顾四周,似乎唯一和我有类似问题的人是 this question但我至少没有发现任何杂散的分号,就像那里的问题一样。

<table>
  <td align="left">
    <div id="wrapper" style="width: 600px;background-image: linear-gradient(#15dbff, #6aff90);margin-top: 0px;position: absolute;top: 0px;">
      <table height="20px" width="600px">
        <tr height="20px" width="600px"></tr>
      </table>
      <div id="heading" style="width: 452px;height: 131px;background-color: white;margin: auto;margin-top: 20px;border-radius: 25px;">
        <img id="headerimg" src="https://kevinuulong.com/images/KLlogocolredcircle.png" style="width: 131px; margin-left: 150px;">
      </div>
      <div id="body" style="width: 392px;background-color: white;margin: auto;margin-top: 20px;border-radius: 25px;padding: 30px;">
        <p id="greeting">Mr. Somebody,</p>
        <p id="mainbody">This is some sample text. It should be using the Montserrat font family. <a href="#" style="text-decoration: none;background: linear-gradient(to right, #15dbff, #6aff90);background-repeat: repeat-x;background-size: 100% 2px;background-position: 0 95%;color: #001744;">This</a>          is what a link should look like. Any images should be inside a div like this.
          <div class="bodyimage" style="width: 392px;height: 200px;overflow: hidden;border-radius: 25px;margin-bottom: 10px;"><img src="https://source.unsplash.com/random/?colors/392x200"></div>
          <div class="bodyimage" style="width: 392px;height: 200px;overflow: hidden;border-radius: 25px;margin-bottom: 10px;"><img src="https://source.unsplash.com/random/?colors/392x200"></div>
        </p>
        <p id="signature">Thanks,<br>Kevin Long</p>
      </div>
      <div id="contact" style="width: 452px;background-color: white;margin: auto;margin-top: 20px;margin-bottom: 20px;border-radius: 25px;">
        <table>
          <th style="width: 50%;"> <img id="contactimg" src="https://kevinuulong.com/images/KLlogocolredcircle.png" style="width: 120px;"></th>
          <th style="width: 50%;"><a href="https://kevinuulong.com" style="text-decoration: none;background: linear-gradient(to right, #15dbff, #6aff90);background-repeat: repeat-x;background-size: 100% 2px;background-position: 0 95%;color: #001744;">kevinuulong.com</a><br><br>
            <a
              id="btn" href="mailto:someone@example.com" style="text-decoration: none;background: #5284ff;background-repeat: repeat-x;background-size: 100% 2px;background-position: 0 95%;color: white;padding-left: 50px;padding-right: 50px;padding-top: 10px;padding-bottom: 10px;border-radius: 20px;">Contact Me</a>
          </th>
        </table>
      </div>
      <table height="20px" width="600px">
        <tr height="20px" width="600px"></tr>
      </table>
    </div>
  </td>
</table>

Example of the stripped style tag

最佳答案

Outlook 的基本要求是,对于每个图像,具有宽度和高度属性,即:

<img width="392" height="200" src="https://source.unsplash.com/random/?colors/392x200">

Div 在 Outlook 中表现不佳;这就是我们仍在使用表格进行布局的原因。

如果您需要图像响应,请在样式中添加:

<img width="392" height="200" style="width:100%;height:auto;max-width:392px" src="https://source.unsplash.com/random/?colors/392x200">

关于html - CSS 从 Outlook Online 中的单个 div 元素中剥离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56178041/

相关文章:

jQuery - 添加元素并影响不同元素的 HTML

c# - 在 ASP.NET C# 中异步发送电子邮件

linux - 如何在 linux 上通过命令行发送嵌入在邮件中的 png 文件?

java - 搜索框的输入文本设计问题

html - Chrome 中 float LI 包装内的链接

css - 通过样式表设置具有匹配父 div attrobite 属性的子 div

jquery - 将 "nephew"draggable 拖动到 "aunt"droppable,同时保持 CSS 和尺寸

email - 本地 SMTP 服务器

html - 中间带有图标的分隔线不会跨越 div 的宽度

javascript - 如何使用书签更改 HTML 元素的值