简体   繁体   English

HTML电子邮件:居中对齐表会影响Internet Explorer中的单元格文本

[英]HTML Emails: Center aligning tables affects cell text in Internet Explorer

I have noticed a 'bug' or whatever with Internet Explorer when viewing HTML emails. 在查看HTML电子邮件时,我注意到Internet Explorer出现“错误”或其他错误。 I'm using Version 11 and its still present. 我正在使用版本11及其仍然存在。

If I want to align a table in the center of the page, it is also causing the text in any <td> cells to be centered, even if I set the attribute to align="left" and use inline CSS to specify text-align="left". 如果我想使表格在页面中心对齐,即使我将属性设置为align="left"并使用内联CSS指定text-align="left".也会导致任何<td>单元格中的文本居中text-align="left".

Here is some example code (try sending this as a HTML email to your yahoo or gmail account and view it in IE): 这是一些示例代码(尝试将其作为HTML电子邮件发送到您的yahoo或gmail帐户,然后在IE中查看):

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#CCC;">
  <tr>
    <td>
    <table width="650px" border="0" align="center" cellpadding="0" cellspacing="0" style="padding-left:11px;padding-right:11px;background:#FFF;">
  <tr>
    <td align="left" valign="top" style="text-align:left;">Moreover, while in most other animals that I can now think of, the eyes are so planted as imperceptibly to blend their visual power, so as to produce one picture and not two to the brain; the peculiar position of the whale's eyes, effectually divided as they are by many cubic feet of solid head, which towers between them like a great mountain separating two lakes in valleys; this, of course, must wholly separate the impressions which each independent organ imparts.<br><br> The whale, therefore, must see one distinct picture on this side, and another distinct picture on that side; while all between must be profound darkness and nothingness to him. Man may, in effect, be said to look out on the world from a sentry-box with two joined sashes for his window. But with the whale, these two sashes are separately inserted, making two distinct windows, but sadly impairing the view. This peculiarity of the whale's eyes is a thing always to be borne in mind in the fishery; and to be remembered by the reader in some subsequent scenes.</td>
  </tr>
</table>
    </td>
  </tr>
</table>

You should see that the text will be center aligned rather than left aligned. 您应该看到文本将居中对齐而不是左对齐。 This 'bug' is only present when viewing the code as an HTML email. 仅当以HTML电子邮件形式查看代码时,才会出现此“错误”。 If you view it as a webpage then it works fine! 如果您将其视为网页,则可以正常工作!

I have tested it using web versions of Outlook and Yahoo as well as a different online mail account and the problem is the same only in IE. 我已经使用Outlook和Yahoo的Web版本以及不同的在线邮件帐户对其进行了测试,并且该问题仅在IE中是相同的。 I tried it in Chrome, Firefox, and Android's built-in browser and it works fine. 我在Chrome,Firefox和Android的内置浏览器中进行了尝试,效果很好。

I don't understand how to fix it other than not to have my tables centered in the middle of the page. 除了不使表格居中位于页面中间之外,我不知道如何解决该问题。 It doesn't look aesthetically pleasing to have my email contents to the left of the page either. 从页面左侧也可以看到我的电子邮件内容,从美学角度来看也不令人满意。

Instead of using align="center" in your parent table tag, try putting it in the parent <td> . 与其在父表标签中使用align="center" ,不如将其放在父<td> Also lose the align="center" on your child table tag, and you don't need CSS text-align: 同时在子表标签上丢失align="center" ,并且您不需要CSS文本对齐:

<table bgcolor="#CCCCCC" width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
      <table bgcolor="#FFFFFF" width="650px" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td align="left" valign="top" style="padding-left:11px; padding-right:11px;">
            Your text here...
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM