html - 为什么此 HTML 代码在 Outlook(HTML 电子邮件)中没有在中间垂直对齐?

标签 html css email outlook html-email

  <table width="378" border="0" cellpadding="0" cellspacing="0">
        <tbody>
              <tr>
                    <td height="30" width="50" bgcolor="#e8e8e8">&nbsp;&nbsp;&nbsp;</td>
                    <td style="color: #ffffff; font-weight: bold; font-family: serif; font-size: 14px; padding-top: 0px; padding-bottom: 0px;" height="30" valign="middle" width="300" align="left" bgcolor="#00aec7">This should vertically center!</td>
              </tr>
        </tbody>
  </table>

在 Gmail 中,它居中,但在 Outlook 中,它位于彩色栏的顶部。我也尝试使用 line-heightvertical-alignvertical-align 不起作用并且 line-height 必须设置为比应有的更小的尺寸(20px 似乎居中,尽管 TD 高 30px)然后使其在 GMail 中顶部对齐!

最佳答案

将文本包装在段落和 span 标记中,并为它们设置 100% 的行高是修复它的唯一更改。 Outlook 用它自己认为“正确”的解释和原始代码的表示替换所有 HTML(通过查看消息源确定此更改)。

<p style="height: 30px; line-height: 100%; margin: 0px; padding: 0px; font-size: 14px;"><span style="margin: 0px; padding: 0px; font-size: 14px;">This should vertically center!</span></p>

使用带有“px”、“pt”或“em”的line-height 无效。只有“100%”有效。

关于html - 为什么此 HTML 代码在 Outlook(HTML 电子邮件)中没有在中间垂直对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28332104/

相关文章:

html - Viewport width=device-width, initial-scale=1 不给我全宽

php - PHP邮件功能无法完成电子邮件的发送

email - 用于测试的干净轻量级邮件服务器

javascript - 使用nodejs运行服务器时"Cannot GET/null"

javascript - 不支持表标签上的自定义数据属性?

javascript - 与固定导航栏重叠的英雄图片幻灯片

java - 使用java从PC发送短信到手机

android - 最小响应菜单(纯 CSS)在 android 默认浏览器上不工作

javascript - 当我导入 BrowserRouter 时,在 reactJS 中遇到此错误 "Error: ENOENT: no such file or directory, stat '/initrd.img'"

javascript - 标签索引在表单中不起作用