【问题标题】:Outlook table spacing in HTML email - no usual tricks workingHTML 电子邮件中的 Outlook 表格间距 - 没有常用的技巧
【发布时间】:2015-11-11 08:13:29
【问题描述】:

我有一个按钮,为了让它在 Outlook 2007/10 (!) 中工作,我必须将三个元素 - 左图、中间文本、右图 - 放在一个更大的表格中它们自己的嵌套表格中。但是,这会导致 Outlook 2007/10 中经常引用的问题,即表格之间存在差距。

下面是按钮的代码。显然,上面有htmlheadbody等。

我已经尝试过在 img 和表格上显示属性、宽度、对齐、边框/填充/边距 = 0...我已经尝试了所有可以在网上找到的解决方案,但没有任何解决方法!

任何其他尝试的想法都非常感激!

注意:这在 Outlook 中全面发生,而不仅仅是其中之一。

<tr>
<td style="width: 15px; font-size: 15px;" valign="top">&#160;</td>
<td align="center" valign="middle">
<table align="center" cellpadding="0" cellspacing="0" height="40" width="243" border="0" style="margin: 0; font-family: 'HelveticaNeue-CondensedBold', 'Arial Narrow', Arial, Helvetica, sans-serif; font-size: 16px; text-align: center; color: #ffffff; height: 40px; mso-table-lspace:0pt; mso-table-rspace:0pt; display: block; background-color: #f2f2f2;" valign="middle">
<tbody valign="middle">
<tr height="40">
    <td height="40">
    <table align="left" border="0" cellpadding="0" cellspacing="0" height="40" width="22" style="margin: 0; border: 0; padding: 0; width: 22px; font-family: 'HelveticaNeue-CondensedBold', 'Arial Narrow', Arial, Helvetica, sans-serif; font-size: 16px; text-align: center; color: #ffffff; height: 40px; background-color: #f2f2f2; mso-table-lspace:0pt; mso-table-rspace:0pt; display: block;" valign="middle">
    <tbody>
    <tr>
        <td height="40" width="22" style="background-color: #f2f2f2;"><a href="#" style="border: 0; text-decoration: none; color: #ffffff;" target="_blank">
        <img align="right" height="40" src="ctaleftgrey.jpg" style="width: 22px; margin: 0; border: 0; padding: 0; text-decoration: none; height: 40px; display: block;" width="22" /></a></td>
    </tr>
    </tbody>
    </table>
    <table align="left" border="0" cellpadding="0" cellspacing="0" height="40" width="180" style="margin: 0; border: 0; padding: 0; font-family: 'HelveticaNeue-CondensedBold', 'Arial Narrow', Arial, Helvetica, sans-serif; font-size: 16px; text-align: center; color: #ffffff; height: 40px; background-color: #ec6608; mso-table-lspace:0pt; mso-table-rspace:0pt; display: block; border-left: 1px solid #ec6608;" valign="middle">
    <tbody>
    <tr style="background-color: #ec6608;">
        <td height="40" style="height: 40px; font-family: 'HelveticaNeue-CondensedBold', 'Arial Narrow', Arial, Helvetica, sans-serif; font-size: 16px; text-align: center; color: #ffffff; background-color: #ec6608; mso-line-height-rule: exactly; line-height: 16px;"><a href="#" style="text-decoration:none; color:#ffffff" target="_blank">Text goes here</a></td>
    </tr>
    </tbody>
    </table>
    <table align="left" border="0" cellpadding="0" cellspacing="0" height="40" width="36" style="margin: 0; border: 0; padding: 0; width: 36px; font-family: 'HelveticaNeue-CondensedBold', 'Arial Narrow', Arial, Helvetica, sans-serif; font-size: 16px; text-align: center; color: #ffffff; height: 40px; background-color: #f2f2f2; mso-table-lspace:0pt; mso-table-rspace:0pt; display: block;" valign="middle">
    <tbody>
    <tr>
        <td height="40" width="36" style="background-color: #f2f2f2;"><a href="#" target="_blank"><img align="right" height="40" src="ctarightgrey.jpg" style="width: 36px; margin: 0; border: 0; padding: 0; text-decoration: none; height: 40px; display: block;" width="36" /></a></td>
    </tr>
    </tbody>
    </table>
    </td>
</tr>
</tbody>
</table>
</td>
<td style="width: 15px; font-size: 15px;" valign="top">&#160;</td>

【问题讨论】:

    标签: html css email outlook


    【解决方案1】:

    这个出乎意料的强悍!我发现部分问题是由外表上的 align="center" 引起的,导致 Outlook 2003 和 Live Mail 中出现 3px 的间隙。如果您仍然需要它与中心对齐,我会将此代码包装在具有该属性的另一个表中。为了解决剩下的问题,我删除了额外的表格并为您的 TD 添加了对齐。我还添加了“border-collapse:collapse;”到你的桌子。您现在应该在桌面 Outlook 客户端中看到没有间距。

    <table cellpadding="0" cellspacing="0" height="40" width="238" border="0" style="border-collapse: collapse; margin: 0; font-family: 'HelveticaNeue-CondensedBold', 'Arial Narrow', Arial, Helvetica, sans-serif; font-size: 16px; text-align: center; max-width:238px; color: #ffffff; width:238px;height: 40px; mso-table-lspace:0pt; mso-table-rspace:0pt; background-color: #f2f2f2;">
    <tbody>
        <tr>
            <td height="40" width="22" align="left">
                        <p style="mso-table-lspace:0;mso-table-rspace:0;margin:0;">
                            <a href="#" style="border: 0; text-decoration: none; color: #ffffff;" target="_blank">
                                <img height="40" src="ctaleftgrey.jpg" style="width: 22px; margin: 0; border: 0; padding: 0; text-decoration: none; height: 40px;" width="22" />
                            </a>
                        </p>
            </td>
            <td height="40" width="180" align="left">
                <table border="0" cellpadding="0" cellspacing="0" height="40" width="180" style="border-collapse: collapse; margin: 0; border: 0; padding: 0; font-family: 'HelveticaNeue-CondensedBold', 'Arial Narrow', Arial, Helvetica, sans-serif; font-size: 16px; text-align: center; color: #ffffff; height: 40px; background-color: #ec6608; mso-table-lspace:0pt; mso-table-rspace:0pt; " valign="middle">
                    <tbody>
                        <tr>
                            <td height="40" style="height: 40px; font-family: 'HelveticaNeue-CondensedBold', 'Arial Narrow', Arial, Helvetica, sans-serif; font-size: 16px; text-align: center; color: #ffffff; background-color: #ec6608; mso-line-height-rule: exactly; line-height: 16px;">
                                <p style="mso-table-lspace:0;mso-table-rspace:0;margin:0;">
                                    <a href="#" style="text-decoration:none; color:#ffffff;border: 0px;" target="_blank">Text goes here</a>
                                </p>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
            <td height="40" width="36" align="left">
                        <p style="mso-table-lspace:0;mso-table-rspace:0;margin:0;">
                            <a href="#" target="_blank">
                                <img height="40" src="ctarightgrey.jpg" style="width: 36px; margin: 0; border: 0; padding: 0; text-decoration: none; height: 40px;" width="36" />
                            </a>
                        </p>
            </td>
        </tr>
    </tbody>
    

    【讨论】:

    • 谢谢 Geoff - 我很兴奋,因为我认为它已经破解了!但它随后会在其他 Outlook(如 2002 年的旧版)中导致新的对齐问题,如下所示:postimg.org/image/bhwlka3yx 我认为 img/nested 表上的 display 属性可能会这样做但没有影响 - 有什么想法吗?跨度>
    • 将一些valigns 扔到表格单元格上:BOOM!休斯顿,我们有对齐!!! @geoff-phillips,你是我最好的新朋友,我爱你!我已经为此奋斗了好几天!!!!
    【解决方案2】:

    我感受到你的痛苦!多年来一直在制作电子邮件模板并与 Outlook 进行这些战斗。答案是你需要尽你所能来让最简单的小部分工作。我会将每个单元格的背景颜色设为橙色,并将左图像左对齐,右对齐https://jsfiddle.net/0gncaogm/

    我还添加了类(以配合您的内联宽度)以使用 overflow-x:hidden 使单元格成为最大宽度...

    img{
        display:inline-block;
        margin-top:0;
        margin-right:0;
        margin-left:0;
        margin-bottom:0;
    }
    .leftedge{
        max-width:15px;
        overflow-x:hidden;
    }
    .rightedge{
        max-width:36px;
        overflow-x:hidden;
    }
    

    在 HTML 中...

    <td height="40" width="36" style="background-color: #e76823;" align="right>    
        <a href="#" target="_blank">
            <img align="right" height="40" src="http://www.tonytansley.co.uk/so/right.jpg" style="width: 36px; margin: 0; border: 0; padding: 0; text-decoration: none; height: 40px; display: block;" width="36" />
        </a>
    </td>
    

    【讨论】:

    • 嗨托尼 - 谢谢,但我试过了,它根本没有任何影响...... :(在上面的图片中看起来完全一样
    【解决方案3】:

    您需要在&lt;table&gt; 标签中指定table-layout。如果这仍然不起作用,您需要将表格布局更改为浮动/显示布局。

     <table style="table-layout: fixed; [.....]">
    

    浮动布局是这样的:

     <a href="..." style="float:left;"><img ....>
    

    【讨论】:

    • 嗨 Marcos - 谢谢,但我尝试添加 table-layout:fixed 无济于事;浮动在电子邮件中很糟糕,通常会让人不安
    • 我正在等待微软杀死 Outlook 和 Internet Explorer 的那一天,但我们对此并不走运
    • 同意...或者更好 - 地球上的每个人都只使用一个与 div 而非表格一起使用的电子邮件系统! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 1970-01-01
    • 2019-02-06
    • 2011-08-27
    相关资源
    最近更新 更多