相当于在Outlook中浮动

时间:2013-07-16 10:29:24

标签: html css outlook html-table html-email

我正在尝试float: left一些表,但刚遇到一个主要问题,outlook不支持float。好吧,然后我尝试使用表格对齐等等,但没有运气。桌子只是彼此相对而不是彼此相邻。人们可以做些什么呢?

PS:它在其他设备上运行得很好,它只有Outlook,我不能给每个表一个td,因为它会打破其他一些东西。

标记:

<table class="products">
   <tr>
      <td align="left" class="test">
         <!-- Product 1  -->
         <table align="center">
            <tr>
               <td class="product">
                  <a href="#">
                     <img src="#"/>
                  </a>
               </td>
            </tr>
         </table>
         <!-- Product 2  -->
         <table align="center">
            <tr>
               <td class="product">
                  <a href="#">
                     <img src="#"/>
                  </a>
               </td>
            </tr>
         </table>
         <!-- Product 3 -->
         <table align="center">
            <tr>
               <td class="product">
                  <a href="#">
                     <img src="#"/>
                  </a>
               </td>
            </tr>
         </table>
         <span class="clear"></span>    
      </td>
   </tr>
 </table>

6 个答案:

答案 0 :(得分:25)

使用width =“”设置每个对齐表格的宽度,而不是CSS。

一个有效的例子:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title></title>
  <style type="text/css">
    table td { border-collapse: collapse; }
    .msoFix { mso-table-lspace:-1pt; mso-table-rspace:-1pt; }
  </style>
</head>
<body style="margin: 0px; padding: 0px; background-color: #FFFFFF;" bgcolor="#FFFFFF">


<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
      <div style="max-width:640px !important;">

        <table class="msoFix" width="320" cellpadding="0" cellspacing="0" align="left" bgcolor="#CCCCCC">
          <tr>
            <td width="15" bgcolor="454545">&nbsp;</td>
            <td width="290" bgcolor="454545" align="left" style="padding: 0px;">&nbsp;<br>Table 1<br>...<br>&nbsp;
            </td>
            <td width="15" bgcolor="454545">&nbsp;</td>
          </tr>
        </table>

        <table class="msoFix" width="320" cellpadding="0" cellspacing="0" align="left" bgcolor="#EEEEEE">
          <tr>
            <td width="15" bgcolor="959595">&nbsp;</td>
            <td width="290" bgcolor="959595" align="left" style="padding: 0px;">&nbsp;<br>Table 2<br>...<br>&nbsp;
            </td>
            <td width="15" bgcolor="959595">&nbsp;</td>
          </tr>
        </table>

      </div>
    </td>
  </tr>
</table>

</body></html>

此外,Outlook在对齐的表之间放置了4-5像素的间隙。将其修改为约1px:

<style type="text/css">
   .msoFix {
      mso-table-lspace:-1pt;
      mso-table-rspace:-1pt;
   }
</style>

要完全摆脱它,你必须为你的表添加边框(另一个Outlook quirk hack)。

答案 1 :(得分:4)

只需将每个子table放入外部td的{​​{1}}。由于table彼此不同,td也是如此。

尝试创建HTML电子邮件时,Code like it’s 1997

答案 2 :(得分:2)

如果你可以忍受让2张牌没有&#34;回应&#34; (一个在彼此之下)在Outlook中,这对我有用:

........
<!--[if gte mso 9]>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
    <td>
<![endif]--> 

<!-- table 1 goes here -->

<!--[if gte mso 9]>
    </td>
    <td>
<![endif]-->

<!-- table 12 goes here -->

<!--[if gte mso 9]>
   </td>
  </tr>
</table>
<![endif]-->
........

答案 3 :(得分:1)

使用一些在线资源,例如:

How To Code HTML Emails

在渲染HTML时,大多数电子邮件客户端都是原始的,会破坏很多格式良好的HTML元素。

以下讨论可能会有所帮助:

What guidelines for HTML email design are there?

一些基本提示:

  • 使用表格进行布局。
  • 将最宽的桌子设置为最大600px宽。
  • 请勿尝试使用JavaScript或Flash
  • 不要在样式标记中使用CSS,因为某些邮件客户端会丢弃它。
  • 仅使用内联CSS样式。

答案 4 :(得分:0)

Outlook.com似乎完全过滤了float个属性,但确实支持display: inline-block 当然,这很可能会破坏您的表格,因为它们依赖于display:table,但它可以帮助您处理任何div

答案 5 :(得分:0)

我知道OP发布这个问题已经很久了,但是我希望它可以帮助需要它的任何人。

如果您需要2列布局,并且还希望它也可以在Outlook中使用,请为每个表提供width左右的45%(为安全起见,请放入{{ 1}}也在那里。如果您将宽度指定为50%,则Outlook(具有自己的功能)会将其呈现为单个列。