在Outlook中,css填充不起作用

Muk*_*esh 46 html css email outlook outlook-2010

我在电子邮件模板中有以下html.

我在MS Outlook和gmail中获得了不同的视图.

<tr>
    <td bgcolor="#7d9aaa" style="color: #fff; font-size:15px; font-family:Arial, Helvetica, sans-serif; padding: 12px 2px 12px 0px; ">
    <span style="font-weight: bold;padding-right:150px;padding-left: 35px;">Order Confirmation </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <span style="font-weight: bold;width:400px;"> Your Confirmation number is {{var order.increment_id}} </span></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

在gmail中

在展望中

如何解决这个问题?

mon*_*ers 48

不幸的是,当谈到EDM时,Outlook是你最大的敌人.当单元格的内容决定单元格尺寸时,某些版本不支持填充.

在邮件客户端中为您提供最一致结果的方法是使用空表格单元格作为填充(我知道,恐怖),但请记住用所需尺寸的空白图像填充这些表格,因为您猜对了,某些版本的Outlook不尊重空单元格的高度/宽度声明.

EDM不是很有趣吗?(不,他们不是.)

  • 什么是EDM? (13认同)
  • 感谢您指向图像,这一定会起作用。顺便说一句,对于那些正在寻找合适图像的人-http://placehold.it是一个非常好的来源,例如https://placeholdit.imgix.net/~text?txtsize=5&amp;bg=f6f6f6&amp;w=15&amp;h=1&amp;txtpad=1 (2认同)
  • @Craig1123 这比电子舞曲更有意义。;) (2认同)

Sac*_*tes 19

避免通讯中的填充和边距,一些电子邮件客户端将忽略此属性。

您可以使用空的trtd建议的(但这会产生大量的 html),或者您可以使用与电子邮件背景颜色相同的边框。所以,而不是padding-top: 40px你可以使用border-top: 40px solid #ffffff(假设电子邮件的背景颜色是#ffffff

我已经在 gmail(和商业 gmail)、雅虎邮件、Outlook Web、Outlook 桌面、雷鸟、苹果邮件等中测试了这个解决方案。据我所知,边界属性在任何地方都可以安全使用。

例子:


<!-- With paddings: WON'T WORK IN ALL EMAIL CLIENTS! -->
<table>

    <tr>

        <td style="padding: 10px 10px 10px 10px">
            <!-- Content goes here -->
        </td>

    </tr>

</table>


<!-- Same result with borders and same border color of the background -->
<table>

    <tr>

        <td style="border: solid 10px #ffffff">
           <!-- Content goes here -->
        </td>

    </tr>

</table>


<!-- Same result using empty td/tr. (A lot more html than borders, get messy on large emails) -->
<table>

    <tr>
        <td colspan="3" height="10" style="height: 10px; line-height: 1px">&nbsp;</td>
    </tr>


    <tr>

        <td width="10" style="width: 10px; line-height: 1px">&nbsp;</td>

        <td><!--Content goes here--></td>

        <td width="10" style="width: 10px; line-height: 1px">&nbsp;</td>

    </tr>


    <tr>
        <td colspan="3" height="10" style="height: 10px; line-height: 1px">&nbsp;</td>
    </tr>

</table>
<!-- With tr/td every property is needed. height must be setted both as attribute and style, same with width, line-height must be setted JIC default value is greater than actual height and without the &nbsp; some email clients won't render the column because is empty. You can remove the colspan and still will work, but is annoying when inspecting the element in browser not to see a perfect square table -->

Run Code Online (Sandbox Code Playgroud)

此外,这里是制作没有媒体查询的响应式新闻通讯的优秀指南。电子邮件确实适用于任何地方:

https://webdesign.tutsplus.com/tutorials/creating-a-future-proof-responsive-email-without-media-queries--cms-23919

并且永远记住使样式内联

https://inliner.cm/

测试电子邮件,这里有一个很好的资源:

https://putsmail.com/

最后,如果您对电子邮件客户端中的 css 支持有疑问,您可以访问这里:

https://templates.mailchimp.com/resources/email-client-css-support/

或在这里:

https://www.campaignmonitor.com/css/

  • 不适用于 Outlook。男人的观点是 cr@p 的一部分。 (6认同)

Muk*_*esh 16

我改为跟随,它对我有用

<tr>
    <td bgcolor="#7d9aaa" style="color: #fff; font-size:15px; font-family:Arial, Helvetica, sans-serif; padding: 12px 2px 12px 0px; ">                              
        <table style="width:620px; border:0; text-align:center;" cellpadding="0" cellspacing="0">               
            <td style="font-weight: bold;padding-right:160px;color: #fff">Order Confirmation </td>                    
            <td style="font-weight: bold;width:260px;color: #fff">Your Confirmation number is {{var order.increment_id}} </td>              
        </table>                    
    </td>
</tr>
Run Code Online (Sandbox Code Playgroud)

基于Bsalex请求更新实际已更改的内容. 我替换了span标签

<span style="font-weight: bold;padding-right:150px;padding-left: 35px;">Order Confirmation </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="font-weight: bold;width:400px;"> Your Confirmation number is {{var order.increment_id}} </span>
Run Code Online (Sandbox Code Playgroud)

表和td标签如下

   <table style="width:620px; border:0; text-align:center;" cellpadding="0" cellspacing="0"> 
      <td style="font-weight: bold;padding-right:160px;color: #fff">Order Confirmation </td>
      <td style="font-weight: bold;width:260px;color: #fff">Your Confirmation number is {{var order.increment_id}} </td>
   </table>
Run Code Online (Sandbox Code Playgroud)

  • 请说明已更改的内容。不要强迫用户使用差异工具。 (23认同)

Rah*_*ane 8

要在电子邮件模板中创建HTML,即电子邮件/简报,填充/边距不支持电子邮件客户端.您可以拍摄1x1尺寸的空白GIF图像并使用它.

<tr>
  <td align="left" valign="top" style="background-color:#7d9aaa;">
    <table width="640" cellspacing="0" cellpadding="0" border="0">
      <tr>
        <td align="left" valign="top" colspan="5"><img style="display:block;" src="images/spacer.gif" width="1" height="10"  alt="" /></td>
      </tr>
      <tr>
        <td align="left" valign="top"><img style="display:block;" src="images/spacer.gif" width="20" height="1"  alt="" /></td>
        <td align="right" valign="top"><font face="arial" color="#ffffff" style="font-size:14px;"><a href="#" style="color:#ffffff; text-decoration:none; cursor:pointer;" target="_blank">Order Confirmation</a></font></td>
        <td align="left" valign="top" width="200"><img style="display:block;" src="images/spacer.gif" width="200" height="1"  alt="" /></td>
        <td align="left" valign="top"><font face="arial" color="#ffffff" style="font-size:14px;">Your Confirmation Number is 260556</font></td>
        <td align="left" valign="top"><img style="display:block;" src="images/spacer.gif" width="20" height="1"  alt="" /></td>
      </tr>
      <tr>
        <td align="left" valign="top" colspan="5"><img style="display:block;" src="images/spacer.gif" width="1" height="10"  alt="" /></td>
      </tr>
    </table>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

  • @AurSaraf我是一名专业的电子邮件开发人员,我可以说编码电子邮件很简单.关于填充/边距 - 仅在"TD"上设置填充.永远不要使用`margin`属性(可能在手机上的媒体查询样式,但绝对不适用于桌面客户端的电子邮件代码部分). (6认同)
  • 所有客户端都支持填充,某些客户端不支持保证金(outlook.com,Lotus Notes) (4认同)
  • 由于这个答案依赖于图像,那么当图像被屏蔽时会发生什么?红色 X 图标会出现在那些小图像的位置吗? (3认同)
  • HTML电子邮件是一个非常可怕的领域,我不确定@Cthulhu是否在这里拖钓:( (2认同)

小智 6

只需使用
<Table cellpadding="10" ..> ... </Table>
不要在MS-Outlook中使用px.Works.

  • ``table>`上的`cellpadding`是不可靠的,就像`cellspacing`一样.最好在`<td>`上使用填充 (7认同)

Sub*_*bbu 5

填充在 Outlook 中不起作用。您可以简单地在元素/文本之前使用多个空格(& nbsp;)来填充左侧,而不是添加空白图像,对于填充顶部或底部,您可以添加一个仅包含空格(& nbsp;)的 div 。这会奏效!!!


Jac*_*cob 5

我遇到了同样的问题,最终实际上使用了border而不是padding.

  • 如果它有效的话会很棒 - 没有在outlook.com上解决 (3认同)