如何在Gmail中使HTML电子邮件响应? [英] How to make html email responsive in gmail?

查看:745
本文介绍了如何在Gmail中使HTML电子邮件响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个完美的雅虎邮件,但没有在Gmail中。由于Gmail不支持标题样式,我将如何添加媒体查询。但我收到了许多电子邮件,这些电子邮件在Gmail移动应用程序。他们是如何做到的?这是怎么回事? 混合设计无需使用媒体查询即可实现响应式的形状转换布局。在它的核心,它使用最大宽度和最小宽度来施加刚性基线(允许一些移动)并为固定到桌面的Outlook添加固定的宽度宽度。一旦设置了适合移动设备的基线,媒体查询会逐步在支持它的客户端(如iOS邮件)中进一步增强电子邮件。



这是一个基本的2列脚手架从 Fabio Carneiro在GitHub上的代码示例(全部归功于他!):

<!doctype html>< html>>< html> < body style =margin:0;> <中心],[ < table border =0cellpadding =0cellspacing =0height =100%width =100%> <! - // 2列支架[中心,流体] - > < TR> < td align =centerheight =100%valign =topwidth =100%> <! - [if mso]> < table align =centerborder =0cellspacing =0cellpadding =0width =660> < TR> < td align =centervalign =topwidth =660>百分比抑制率ENDIF] - GT!; < table align =centerborder =0cellpadding =0cellspacing =0width =100%style =max-width:660px;> < TR> < td align =centervalign =topstyle =font-size:0;> <! - //开发者注意事项:1.设置font-size:0;有必要确保在包裹每一列的定心格之间没有引入额外的间距。 // - > <! - [if mso]> < table align =centerborder =0cellspacing =0cellpadding =0width =660> < TR> < td align =leftvalign =topwidth =330>百分比抑制率ENDIF] - GT!; < div style =display:inline-block; max-width:50%; min-width:240px; vertical-align:top; width:100%;> <! - //开发人员注意事项:1.为了让每列都以堆叠为中心,将它们包装在单独的div中,设置与其中的表格相同的最大宽度和宽度,并将显示设置为内联块;使用垂直对齐是可选的。 2.设置最小宽度决定了该块的两列何时换行;在这种情况下,当总可用宽度小于或等于480像素。 // - > < table align =leftborder =0cellpadding =0cellspacing =0width =100%style =max-width:330px;> < TR> < td align =centervalign =top> <! - //用BLOCK替换 - > < p style =background-color:#2BAADF; color:#FFFFFF; font:16px Helvetica,sans-serif,normal; margin:0!important; padding:10px;> LEFT< / p> <! - 用块代替// - > < / TD> < / TR> < /表> < / DIV> <! - [if mso]> < / TD> < td align =leftvalign =topwidth =330>百分比抑制率ENDIF] - GT!; < div style =display:inline-block; max-width:50%; min-width:240px; vertical-align:top; width:100%;> < table align =leftborder =0cellpadding =0cellspacing =0width =100%style =max-width:330px;> < TR> < td align =centervalign =top> <! - //用BLOCK替换 - > < p style =background-color:#51BBE5; color:#FFFFFF; font:16px Helvetica,sans-serif,normal; margin:0!important; padding:10px;> RIGHT< / p> <! - 用块代替// - > < / TD> < / TR> < /表> < / DIV> <! - [if mso]> < / TD> < / TR> < /表>百分比抑制率ENDIF] - GT!; < / TD> < / TR> < /表> <! - [if mso]> < / TD> < / TR> < /表>百分比抑制率ENDIF] - GT!; < / TD> < / TR> <! - 2 - 列支架[中心,流体] // - > < /表> < /中心],[ < / body>< / html>

脚手架和模式在回购和其他地方,但这显示了行动的基本原则。


I've built an html email which is perfect in yahoo but not in gmail. As gmail does not support header style how will i add media query. But I got many email which are responsive in gmail mobile. How they made that? what's the way?

解决方案

Hybrid Design achieves a responsive, shape-shifting layout without using media queries. At its core, it uses max-width and min-width to impose rigid baselines (allowing some movement) and imposes a fixed, wide width for Outlook who is shackled to desktop anyway. Once a mobile-friendly baseline is set, media queries progressively enhance the email further in clients that support it (like iOS Mail).

Here is a basic 2-column scaffolding from Fabio Carneiro's code samples on GitHub (all credit to him!):

<!doctype html>
<html>
	<body style="margin:0;">
		<center>
			<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">




				<!-- // 2-COLUMN SCAFFOLD [CENTERING, FLUID] -->
				<tr>
					<td align="center" height="100%" valign="top" width="100%">
						<!--[if mso]>
						<table align="center" border="0" cellspacing="0" cellpadding="0" width="660">
						<tr>
						<td align="center" valign="top" width="660">
						<![endif]-->
						<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:660px;">
							<tr>
								<td align="center" valign="top" style="font-size:0;">
									<!--// DEVELOPER NOTES:
										1. Setting font-size:0; is necessary to ensure
										   that there is no extra spacing introduced
										   between the centering divs that wrap each
										   of the columns. //-->

									<!--[if mso]>
									<table align="center" border="0" cellspacing="0" cellpadding="0" width="660">
									<tr>
									<td align="left" valign="top" width="330">
									<![endif]-->
									<div style="display:inline-block; max-width:50%; min-width:240px; vertical-align:top; width:100%;">
										<!--// DEVELOPER NOTES:
											1. To have each column center upon stacking,
											   wrap them in individual divs, set the same
											   max-width and width as the table within it,
											   and set display to inline-block; using
											   vertical-align is optional.

											2. Setting min-width determines when the two
											   columns of this block will wrap; in this
											   case, when the total available width is
											   less than or equal to 480px. //-->

										<table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:330px;">
											<tr>
												<td align="center" valign="top">
	
													<!-- // REPLACE WITH BLOCK -->
													<p style="background-color:#2BAADF; color:#FFFFFF; font:16px Helvetica, sans-serif, normal; margin:0 !important; padding:10px;">LEFT</p>
													<!-- REPLACE WITH BLOCK // -->
	
												</td>
											</tr>
										</table>
									</div>
									<!--[if mso]>
									</td>
									<td align="left" valign="top" width="330">
									<![endif]-->
									<div style="display:inline-block; max-width:50%; min-width:240px; vertical-align:top; width:100%;">
										<table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width:330px;">
											<tr>
												<td align="center" valign="top">
	
													<!-- // REPLACE WITH BLOCK -->
													<p style="background-color:#51BBE5; color:#FFFFFF; font:16px Helvetica, sans-serif, normal; margin:0 !important; padding:10px;">RIGHT</p>
													<!-- REPLACE WITH BLOCK // -->	
	
												</td>
											</tr>
										</table>
									</div>
									<!--[if mso]>
									</td>
									</tr>
									</table>
									<![endif]-->
								</td>
							</tr>
						</table>
						<!--[if mso]>
						</td>
						</tr>
						</table>
						<![endif]-->
					</td>
				</tr>
				<!-- 2-COLUMN SCAFFOLD [CENTERING, FLUID] // -->




			</table>
		</center>
	</body>
</html>

There are more scaffolds and patterns in that repo and elsewhere, but this shows the basic principle in action.

这篇关于如何在Gmail中使HTML电子邮件响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆