HTML邮件中替代table背景图的无div方案(适配Outlook旧版本)
纯Table结构兼容Outlook 2007/2010/2016的背景图解决方案
Absolutely, you can fix this with a pure table-based approach that works for Outlook 2007-2016 (powered by the Word rendering engine) and all other email clients. The trick is using VML (Vector Markup Language) specifically for Outlook, while keeping standard CSS background images for modern clients—all without a single div in sight.
How this works:
- Outlook 2007+ ignores
background-imagein CSS for tables, but it supports VML for background visuals. We wrap the VML code in Outlook-only conditional comments so only those clients render it. - For every other email client, the standard
background-imageCSS on the table will handle the background as expected. - All your content stays nested in table cells, so you keep the rock-solid compatibility tables provide for emails.
Updated Pure Table Code:
<table border="0" cellpadding="0" cellspacing="0" style="max-width:692px; background-image: url(https://cdn2.hubspot.net/hubfs/3055391/Inbound/CPD%202017/Email/Newsletter%20%20-%20Customers/header-image.png); background-size: cover; background-position: center;" width="692" height="400"> <tbody> <tr> <td valign="top" align="center" style="font-family:'Open Sans',Helvetica,Arial,sans-serif;padding:25px 28px;"> <!--[if mso]> <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width:692px;height:400px;"> <v:fill type="tile" src="https://cdn2.hubspot.net/hubfs/3055391/Inbound/CPD%202017/Email/Newsletter%20%20-%20Customers/header-image.png" color="#ffffff" /> <v:textbox inset="0,0,0,0"> <![endif]--> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody> <tr> <td align="left" style="font-family:'Open Sans',Helvetica,Arial,sans-serif;"> <a href="#" target="_blank"> <img alt="LOGO" src="#" style="display:block;border:0px; font-family:Helvetica,Arial,sans-serif;color:#ffffff"> </a> </td> <!-- SOCIAL ICONS --> <td style="text-align: right;"> <!--YouTube --> <a href="#"><img src="https://cdn2.hubspot.net/hubfs/3055391/Inbound/CPD%202017/Email/Newsletter%20%20-%20Customers/youtube-icon.png" style="display:block;border:0; margin-left:8px;"></a> <!--Twitter --> <a href="#"><img src="https://cdn2.hubspot.net/hubfs/3055391/Inbound/CPD%202017/Email/Newsletter%20%20-%20Customers/twitter-icon.png" style="display:block;border:0; margin-left:8px;"></a> <!--LinkedIn --> <a href="#"><img src="https://cdn2.hubspot.net/hubfs/3055391/Inbound/CPD%202017/Email/Newsletter%20%20-%20Customers/linkedin-icon.png" style="display:block;border:0; margin-left:8px;"></a> <a href="#"><img src="https://cdn2.hubspot.net/hubfs/3055391/Inbound/CPD%202017/Email/Newsletter%20%20-%20Customers/facebook-icon.png" style="display:block;border:0; margin-left:8px;"></a> </td> </tr> <!-----------------> <!-- HEADER TEXT --> <!-----------------> <tr> <td colspan="2" style="padding-top:40px;"> <!-- PADDING--> </td> </tr> <tr> <td colspan="2" style="height: 100px; color: #fff; font-family:'Open Sans',Helvetica,Arial,sans-serif; text-align: center; font-size: 26px; padding-bottom: 10px; text-transform: uppercase;"> TEXT<br> HERE </td> </tr> </tbody> </table> <!--[if mso]> </v:textbox> </v:rect> <![endif]--> </td> </tr> </tbody> </table>
Quick Breakdown of Key Changes:
- The VML block is wrapped in
<!--[if mso]>and<![endif]-->so only Outlook processes it. Thev:rectmatches your table's exact dimensions, andv:fillloads your background image. - For non-Outlook clients, I added
background-size: coverandbackground-position: centerto the table's style to ensure the background scales properly. - I updated the social icons with
display:block;border:0and left margins to fix common spacing glitches in email clients. - Every piece of content is still inside table elements—no divs were harmed in the making of this solution.
内容的提问来源于stack exchange,提问作者Freddy
相关产品推荐
相关产品推荐

