简体   繁体   English

HTML 电子邮件对齐文本

[英]HTML email align text

I am trying to align a part of text to the right and the other part to the left in an HTML mail but in Outlook the float doesn't work.我试图在 HTML 邮件中将一部分文本右对齐,另一部分左对齐,但在 Outlook 中float不起作用。 So basically I am looking for float CSS in Outlook.所以基本上我在 Outlook 中寻找float CSS。 I know it sounds pretty creepy and text-align or align="" didn't work.我知道这听起来很令人毛骨悚然,而且text-alignalign=""没有用。 Any suggestions?有什么建议么?

<td>
   <span style="text-align:left; float:left;">
       First part
   </span>
   <span style="text-align:right; float:right;">
       Second part
   </span>
</td>

Honestly, if you're doing an HTML email I'd stick to using tables.老实说,如果您正在处理 HTML 电子邮件,我会坚持使用表格。 Not all CSS selectors are available in all email clients and you'll drive yourself mad trying to do it any other way.并非所有的电子邮件客户端都可以使用所有 CSS 选择器,如果您想以任何其他方式这样做,您会发疯。 HTML emails are like the web 5 years ago. HTML 电子邮件就像 5 年前的网络。

There are a couple of good documents on the subject:有几个关于这个主题的好文件:

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

http://www.emailology.org/ http://www.emailology.org/

For your example:对于您的示例:

 <td> <table cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left">First part</td> <td align="right">Second part</td> </tr> </table> </td>

It's horrible but unfortunately it's still the best way.这很可怕,但不幸的是,它仍然是最好的方法。

Use ( shudder ) layout tables.使用(颤抖)布局表。

Outlook's support for styling of email is so awful that there isn't any other way. Outlook 对电子邮件样式的支持是如此糟糕,以至于没有其他方法。

There is a 24 ways article with some general advice for writing HTML formatted email.一篇关于编写 HTML 格式电子邮件的24 种方法的文章,其中包含一些一般性建议。

<p align="right">My right content</p>

它应该可以解决问题,因为它是 HTML1。

I had a similar issue.我有一个类似的问题。 I wanted to center three images in the footer of my email.我想将三张图片放在电子邮件页脚的中央。 I got it to work like this.我让它像这样工作。

            <div style="display:inline-flex; width:100%;">
                <img style="width: 15%; height:fit-content; margin: 0 7.5%;" src="https://example.com/employment-ontario.png" alt='img-logo0'/>
                <img style="width: 15%; height:fit-content; margin: auto 7.5%;" src="https://example.com/canada-logo.png" alt='img-logo1'/>
                <img style="width: 15%; height:fit-content;  margin: auto 7.5%;" src="https://example.com/ontario-govt.png" alt='img-logo2'/> 
            </div> 

the image with margin: 0 7.5% is the largest of all the images (if you want to imitate align-items: center set the other two to images to margin: auto 7.5% , they will automatically center your images.带有margin: 0 7.5%的图像是所有图像中最大的(如果你想模仿align-items: center将另外两个设置为 images to margin: auto 7.5% ,它们会自动将你的图像居中。

Note: In this example 7.5% is for only one side of your container, so total margin on the left and right will be 15%.注意:在本例中,7.5% 仅适用于容器的一侧,因此左侧和右侧的总边距将为 15%。 for one img, giving a total of 45% used.对于一个 img,总共使用了 45%。

Sum of mine is 90%, but you get the idea.我的总和是 90%,但你明白了。

Image of what it looks like below.下面的图像。

在此处输入图像描述

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

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