我正在创建一个基于this的响应式电子邮件模板。
我在Gmail,雅虎,Outlook.com等大多数手机上都有它的工作方式,但我无法解决为什么桌面上的Outlook不喜欢它。我希望电子邮件的宽度不要超过662px。
截图:
Outlook
Apple Mail(我希望它看起来如何)
这是代码,我每次发送测试之前都使用MailChimps CSS inliner tool。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- If you delete this tag, the sky will fall on your head -->
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>XXX</title>
<style type="text/css">
/* -------------------------------------
GLOBAL
------------------------------------- */
* {
margin:0;
padding:0;
}
* { font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif; }
img {
max-width: 100%;
}
.collapse {
margin:0;
padding:0;
}
body {
-webkit-font-smoothing:antialiased;
-webkit-text-size-adjust:none;
width: 100%!important;
height: 100%;
}
/* -------------------------------------
ELEMENTS
------------------------------------- */
a { color: #2BA6CB;}
p.callout {
padding:15px;
background-color:#ECF8FF;
margin-bottom: 15px;
}
.callout a {
font-weight:bold;
color: #2BA6CB;
}
table.social {
/* padding:15px; */
background-color: #ebebeb;
}
/* -------------------------------------
HEADER
------------------------------------- */
table.head-wrap { width: 100%;}
.header.container table td.logo { padding: 15px; }
.header.container table td.label { padding: 15px; padding-left:0px;}
/* -------------------------------------
BODY
------------------------------------- */
table.body-wrap { width: 100%;}
/* -------------------------------------
FOOTER
------------------------------------- */
table.footer-wrap { width: 100%; clear:both!important;
}
.footer-wrap .container td.content p { border-top: 1px solid rgb(215,215,215); padding-top:15px;}
.footer-wrap .container td.content p {
font-size:10px;
font-weight: bold;
}
/* -------------------------------------
TYPOGRAPHY
------------------------------------- */
h3 {
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; line-height: 1.1; margin-bottom:15px; color:#000;
}
h3 { font-weight:500; font-size: 60px; color:red;}
.collapse { margin:0!important;}
p, ul {
margin-bottom: 10px;
font-weight: bold;
font-size:14px;
line-height:1.6;
color: #5B6063;
}
/* ---------------------------------------------------
RESPONSIVENESS
Nuke it from orbit. It's the only way to be sure.
------------------------------------------------------ */
/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
.container {
display:block!important;
max-width:662px!important;
margin:0 auto!important; /* makes it centered */
clear:both!important;
}
/* This should also be a block element, so that it will fill 100% of the .container */
.content {
padding:15px;
max-width:662px;
margin:0 auto;
display:block;
}
.mainBg {
background-color: #CCCCCC;
background-image: url('http://placehold.it/643x638');
/*background-image: url('XXX_BG_2.jpg');
background-size: 100%;*/
background-repeat: repeat-x;
}
.mainOverlay {
width: 375px;
margin:0 auto;
background-color: #FFFFFF;
border-style: solid;
border-width: 1px;
border-color: #cccccc;
}
.overlayText {
width: 240px;
margin: 0 auto;
}
/* Let's make sure tables in the content area are 100% wide */
.content table { width: 100%; }
/* Odds and ends */
.column {
width: 300px;
float:left;
}
.column tr td { padding: 15px; }
.column-wrap {
padding:0!important;
margin:0 auto;
max-width:662px!important;
}
.column table { width:100%;}
/* Be sure to place a .clear element after each set of columns, just to be safe */
.clear { display: block; clear: both; }
/* -------------------------------------------
PHONE
For clients that support media queries.
Nothing fancy.
-------------------------------------------- */
@media only screen and (max-width: 662px) {
a[class="btn"] { display:block!important; margin-bottom:10px!important; background-image:none!important; margin-right:0!important;}
div[class="column"] { width: auto!important; float:none!important;}
table.social div[class="column"] {
width:auto!important;
}
p, ul {
margin-bottom: 10px!important;
font-weight: normal!important;
font-size:11px!important;
line-height:1.6!important;
}
.mainOverlay {
max-width: 220px!important;
margin:0 auto!important;
background-color: #FFFFFF!important;
border-style: solid!important;
border-width: 1px!important;
border-color: #cccccc!important;
}
.overlayText {
width: 170px!important;
margin:0 auto!important;
}
h3 {
font-weight:500!important;
font-size: 27px!important;
color:red!important;
}
}
</style>
</head>
<body bgcolor="#FFFFFF">
<!-- HEADER -->
<table class="head-wrap" bgcolor="#FFFFFF">
<tr>
<td></td>
<td class="header container">
<div class="content">
<table bgcolor="#FFFFFF">
<tr>
<td>
<a href="#"><img src="http://placehold.it/240x40" /></a>
<a href="#"><img src="http://placehold.it/69x18" /></a>
<a href="#"><img src="http://placehold.it/94x18" /></a>
<a href="#"><img src="http://placehold.it/73x18" /></a>
<a href="#"><img src="http://placehold.it/86x18" /></a>
</td>
</tr>
</table>
</div>
</td>
<td class="header container">
<div class="content">
<table bgcolor="#FFFFFF">
<tr>
<td align="center" style="border-top: solid #cccccc 1px; border-bottom: solid #cccccc 1px; font-size:11px;"><span style="color: rgb(44,147,221)">FREE SHIPPING</span> ON ORDERS OVER XXX</td>
</tr>
</table>
</div>
</td>
<td></td>
</tr>
</table>
<!-- /HEADER -->
<!-- BODY -->
<table class="body-wrap">
<tr>
<td></td>
<td class="container" bgcolor="#FFFFFF">
<div class="content">
<div class="mainBg">
<table>
<tr>
<td align="center">
<br />
<h3 align="center">JOYEUX ANNIVERSAIRE!</h3>
Dear XXXX,
<br /><br />
<span style="font-weight:bold;">Happy Birthday from XXX!</span>
<br /><br />
To celebrate your special day,
we’re giving you <span style="color: red">$XX</span> to spend
at our online store.
<br /><br />
Simply enter the code
<span style="color: red">XXX</span> at checkout.
<br /><br />
Your offer is valid for the next XX days.
Enjoy!
<br /><br />
<a href="#"><img src="http://placehold.it/203x38" /></a>
<p> </p>
<span class="clear"></span>
</td>
</tr>
</table>
</div>
</div>
</td>
<td></td>
</tr>
</table>
<!-- /BODY -->
<!-- FOOTER -->
<table class="footer-wrap">
<tr>
<td></td>
<td class="container">
<div class="content">
<table>
<tr>
<td align="center">
<p>
<a href="#"><img src="http://placehold.it/125x16" /></a>
<a href="#"><img src="http://placehold.it/21x37" /></a>
<a href="#"><img src="http://placehold.it/23x37" /></a>
<a href="#"><img src="http://placehold.it/21x37" /></a>
<a href="#"><img src="http://placehold.it/22x37" /></a>
<a href="#"><img src="http://placehold.it/22x37" /></a>
<a href="#"><img src="http://placehold.it/22x37" /></a>
<a href="#"><img src="http://placehold.it/110x37" /></a>
</p>
</td>
</tr>
</table>
</div>
</td>
<td></td>
</tr>
</table>
<!-- /FOOTER -->
</body>
</html>
内联:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<title style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">XXX</title>
</head>
<body bgcolor="#FFFFFF" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-webkit-text-size-adjust: none;height: 100%;width: 100%;">
<!-- HEADER -->
<table class="head-wrap" bgcolor="#FFFFFF" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;width: 100%;">
<tr style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<td style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"></td>
<td class="header container" style="margin: 0 auto;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;display: block;max-width: 662px;clear: both;">
<div class="content" style="margin: 0 auto;padding: 15px;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 662px;display: block;">
<table bgcolor="#FFFFFF" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;width: 100%;">
<tr style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<td style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/240x40" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/69x18" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/94x18" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/73x18" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/86x18" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
</td>
</tr>
</table>
</div>
</td>
<td class="header container" style="margin: 0 auto;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;display: block;max-width: 662px;clear: both;">
<div class="content" style="margin: 0 auto;padding: 15px;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 662px;display: block;">
<table bgcolor="#FFFFFF" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;width: 100%;">
<tr style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<td align="center" style="border-top: solid #cccccc 1px;border-bottom: solid #cccccc 1px;font-size: 11px;margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"><span style="color: rgb(44,147,221);margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">FREE SHIPPING</span> ON ORDERS OVER XXX</td>
</tr>
</table>
</div>
</td>
<td style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"></td>
</tr>
</table>
<!-- /HEADER -->
<!-- BODY -->
<table class="body-wrap" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;width: 100%;">
<tr style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<td style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"></td>
<td class="container" bgcolor="#FFFFFF" style="margin: 0 auto;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;display: block;max-width: 662px;clear: both;">
<div class="content" style="margin: 0 auto;padding: 15px;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 662px;display: block;">
<div class="mainBg" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;background-color: #CCCCCC;background-image: url(http://placehold.it/643x638);background-repeat: repeat-x;">
<table style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;width: 100%;">
<tr style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<td align="center" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<h3 align="center" style="margin: 0;padding: 0;font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;line-height: 1.1;margin-bottom: 15px;color: red;font-weight: 500;font-size: 60px;">JOYEUX ANNIVERSAIRE!</h3>
Dear XXXX,
<br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"><br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<span style="font-weight: bold;margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">Happy Birthday from XXX!</span>
<br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"><br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
To celebrate your special day,
we’re giving you <span style="color: red;margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">$XX</span> to spend
at our online store.
<br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"><br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
Simply enter the code
<span style="color: red;margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">XXX</span> at checkout.
<br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"><br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
Your offer is valid for the next XX days.
Enjoy!
<br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"><br style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/203x38" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<p style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;margin-bottom: 10px;font-weight: bold;font-size: 14px;line-height: 1.6;color: #5B6063;"> </p>
<span class="clear" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;display: block;clear: both;"></span>
</td>
</tr>
</table>
</div>
</div>
</td>
<td style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"></td>
</tr>
</table>
<!-- /BODY -->
<!-- FOOTER -->
<table class="footer-wrap" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;width: 100%;clear: both;">
<tr style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<td style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"></td>
<td class="container" style="margin: 0 auto;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;display: block;max-width: 662px;clear: both;">
<div class="content" style="margin: 0 auto;padding: 15px;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 662px;display: block;">
<table style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;width: 100%;">
<tr style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<td align="center" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;">
<p style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;margin-bottom: 10px;font-weight: bold;font-size: 14px;line-height: 1.6;color: #5B6063;">
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/125x16" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/21x37" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/23x37" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/21x37" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/22x37" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/22x37" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/22x37" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
<a href="#" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;color: #2BA6CB;"><img src="http://placehold.it/110x37" style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;max-width: 100%;"></a>
</p>
</td>
</tr>
</table>
</div>
</td>
<td style="margin: 0;padding: 0;font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;"></td>
</tr>
</table>
<!-- /FOOTER -->
</body>
</html>
非常感谢任何帮助,谢谢。
编辑:添加了截图
答案 0 :(得分:3)
在容器上设置中心对齐方式,它将解决您的问题。
我正在粘贴的代码也提出了一些您可以利用的额外改进。
<center>
<table width="100%" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>YOUR EMAIL CONTENT NESTED HERE</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
答案 1 :(得分:0)
您不能依赖Outlook的最大宽度。查看here,这是一个很好的资源,可以显示哪些电子邮件客户端接受不同的css属性。如果你想要一些看起来很好的东西,我肯定会使用Zurb's boilerplate css and html。看起来这就是你正在使用的,但尽可能贴近。您必须非常小心地编写跨客户端电子邮件。这需要花费大量时间和调试。
编辑:此外,通常建议电子邮件模板的宽度不超过600像素。
答案 2 :(得分:0)
你要求的实际上是一种流畅的最大宽度技术,而不是响应式技术(尽管你需要利用媒体查询为Outlook '11做这个。)
见this link。只需用自己的内部表格换出内部表格,然后将宽度从600更改为您需要的宽度。