如何在Outlook的HTML邮件模板中实现背景图文本居中对齐?
Got it, let's tackle this Outlook VML issue—those old versions can be tricky with background images and text alignment! The problem here is that Outlook's VML text box doesn't inherit the CSS centering from the <td>; you have to explicitly set alignment properties directly on the VML elements.
Here's what you need to modify in your code:
- Add VML-specific alignment styles to the
<v:textbox>element:- Use
v-text-anchor:middleto achieve vertical centering (this is a VML-native property for vertical alignment) - Add
text-align:centerto ensure horizontal centering within the text box
- Use
- Double-check that the
<v:rect>dimensions match your<td>exactly (you already have this right, but consistency here helps avoid layout shifts)
Modified Working Code:
<table cellpadding="0" cellspacing="0" border="0" width="600" height="100" align="center"> <tr> <td background="https://picsum.photos/600/100" bgcolor="#ffffff" width="530" height="95" valign="middle" style="background-image: url('https://picsum.photos/600/100');background-repeat:no-repeat; text-align:center; vertical-align:middle;"> <!--[if gte mso 9]> <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width:530px;height:95px;color:#ffffff"> <v:fill type="tile" src="https://picsum.photos/600/100" color="#ffffff" /> <!-- Added VML-specific alignment styles here --> <v:textbox inset="0,0,0,0" style="v-text-anchor:middle; text-align:center;"> <![endif]--> <p style="font-family:Arial, Helvetica, sans-serif; font-size:40px; color:#ffffff; margin: 0;">Your quarterly Update</p> <!--[if gte mso 9]> </v:textbox> </v:rect> <![endif]--> </td> </tr> </table>
Why your previous CSS didn't work:
Outlook (especially older versions) ignores most modern CSS properties like position:absolute when rendering VML content. You have to use VML-native attributes and styles to control alignment within the VML text box—this is the only reliable way to get consistent centering across Outlook and other email clients.
内容的提问来源于stack exchange,提问作者Rahul Kashyap

