简体   繁体   English

有关HTML电子邮件时事通讯的CSS编码标准的困惑

[英]Confusion about css coding standards for Html Email newsletter

i am coding Email newsletters. 我正在编写电子邮件通讯。 i have seen some guidelines regarding Good email coding.. i want to ask about css code for Email newsletters for example its preffered to code inline css but for some free templates i found code like this 我已经看到一些有关良好电子邮件编码的准则。.我想询问有关电子邮件新闻稿的CSS代码,例如,它倾向于对内联CSS进行编码,但是对于一些免费模板,我发现了这样的代码

       <style type="text/css">

       body { color:#000; background-color:#fff; font-family:Arial, Helvetica, sansserif; text-align:center; }
       h2 { color:#2255DB; font-size:16px; margin-top:15px; margin-bottom:0px; }        
       h2 a:link { text-decoration:none; }
      .footer { fontsize:11px; text-align:center; color:#2255DB; }// and son on 

       </style>

in body code for fotter is like 在人的身体代码就像

    <p class="footer" style="color:#2255DB;"> footer...</footer>//again style  tag

and sometimes i found like this total inline styling .. 有时我发现像这样的整体内联样式..

    <span style="font-weight: bold; width: 525px;">
    Lorem ipsum dolo
    </span><br><br>// and son on  ,,  

Both the above mentioned codes are working fine in Email clients i have also seen standards from Campaign monitor etc, so i am confused which style is better .. should we use style in as in above mentioned code and or total inline coding , Please if someone can clear me about this ..it would be great favor 上面提到的两个代码在电子邮件客户端中都可以正常工作,我也已经从Campaign Monitor等中看到了标准,所以我很困惑哪种样式更好。.我们是否应该像上面提到的代码中那样使用样式和/或整体内联代码,如果有人可以使我明白这一点。

EDIT : once coded is there any free service that can help to check if its valid code for mail clients ? 编辑 :一旦编码,有没有免费的服务可以帮助检查邮件客户端的有效代码?

Many mail clients will remove embedded stylesheets. 许多邮件客户端将删除嵌入式样式表。 It's best to use inline styles for everything. 最好对所有内容都使用内联样式。

In your example, you're styling the BODY tag - but if I read your email in Gmail - the page already has its OWN body tag - so yours will be stripped out. 在您的示例中,您正在设置BODY标签的样式-但是,如果我在Gmail中阅读了您的电子邮件,则该页面已经具有OWN正文标签-因此您的邮件将被剥离。

I've found the campaign monitor guide to be an excellent resource to follow. 我发现广告系列监控指南是一个很好的参考资源。

Here's a good test: save your email at a static HTML page, then open it on MS Word. 这是一个很好的测试:将电子邮件保存在静态HTML页面上,然后在MS Word上打开它。 It's a pretty good "worst-case scenario". 这是一个非常好的“最坏情况”。

If you are going to be doing any serious email marketing work, Exact Target has an excellent tool that will actually render-out your email in different clients and give you a PDF of screen shots from those platforms to review. 如果您打算进行任何认真的电子邮件营销工作, Exact Target有一个出色的工具,它实际上可以在不同的客户端中呈现您的电子邮件,并为您提供这些平台的屏幕截图PDF以供查看。

From the HTML emails I have done, as well as following the advice from http://24ways.org/2009/rock-solid-html-emails/ , I would recommend always putting styles inline. 从我已经完成的HTML电子邮件中,以及按照http://24ways.org/2009/rock-solid-html-emails/的建议,我建议始终将样式置于内联。

You mentioned http://www.campaignmonitor.com/css/ , which does show that Gmail would be the client where styles would have issues not being inline. 您提到了http://www.campaignmonitor.com/css/ ,它确实表明Gmail将成为客户端,其中样式不会出现内联问题。

Edit: If there is any interest on why Gmail is the black sheep in this scenario, check out Section 1194.22, http://mail.google.com/mail/help/accessibility.html 编辑:如果对这种情况下的Gmail为什么是败类感兴趣,请查看第1194.22节, http://mail.google.com/mail/help/accessibility.html。

To make sure that the HTML newsletter looks as close as the designs I would definitely use inline styling. 为了确保HTML时事通讯看起来和设计一样紧密,我肯定会使用内联样式。

Unfortunately you have to be very specific with your styling, otherwise some software (Gmail for instance) will override your style declarations. 不幸的是,您必须非常明确自己的样式,否则某些软件(例如Gmail)将覆盖您的样式声明。 It is a real pain sometimes, but it's worth doing it that way IMO. 有时确实很痛苦,但值得IMO这样做。

Same thing goes for HTML email signatures. HTML电子邮件签名也是如此。

So definitely go for the inline styling :) 所以绝对要使用内联样式:)

Oh, and one more thing. 哦,还有一件事。 I know that it's 2012 and loads of designers/front-enders advice to use html tags (even html5 elements) in HTML emails and signatures, but I'd try to stick to the old-school way and use tables to make sure there is no unnecessary artefacts with the code. 我知道这是2012年,并且有大量的设计师/前者建议在HTML电子邮件和签名中使用html标签(甚至是html5元素),但我会尽量遵循传统的方法,并使用表格来确保该代码没有不必要的伪像。

For email newsletter formats, as different email clients renders the layouts differently, I would strongly suggest you use inline css and primarily font tag and its attributes to styling the texts. 对于电子邮件新闻稿格式,由于不同的电子邮件客户端以不同的方式呈现布局,因此我强烈建议您使用内联css (主要是字体标签及其属性)来设置文本样式。 Also use Table structure instead of div layouts to keep the layout consistent across most of the email clients. 也可以使用表格结构代替div布局,以使大多数电子邮件客户端之间的布局保持一致。

Creating HTML templates for email is a real hassle. 为电子邮件创建HTML模板确实很麻烦。 Testing is also often extremely difficult and unreliable, even from services which say they test everything. 测试也通常极其困难且不可靠,即使从表示已测试所有内容的服务中也是如此。 Older mail clients are known to ignore CSS and newer HTML elements. 已知较旧的邮件客户端会忽略CSS和较新的HTML元素。 Additionally, a mail client may override some of your CSS with its own, mangling the layout. 此外,邮件客户端可能会使用其自己的CSS覆盖布局,从而覆盖某些CSS。

My advice: 我的建议:

1) Use inline styles, as other people mentioned. 1)使用内联样式,如其他人所述。 Apply them to EVERYTHING. 将它们应用于一切。 For example, don't expect adding a font-size to a div to apply to a <p> inside the div (as it should!). 例如,不要指望在div中添加字体大小以应用于div内部的<p> (应该如此!)。 Add the style to both, or at least the immediate parent. 将样式添加到两者,或至少添加直接父样式。

2) Use tables for any layout (ugh!), rather than margins and paddings. 2)使用表格进行任何布局(ugh!),而不要使用边距和填充。 Some older mail clients could care less about CSS, and may strip all of yours out, or only apply snippets of it. 一些较旧的邮件客户端可能不太关心CSS,可能会剥离所有CSS,或仅应用其中的摘要。

3) Design the email in a way that it is still readable even if the email client discards all your CSS (which is a distinct possibility). 3)以电子邮件仍然可读的方式设计电子邮件,即使电子邮件客户端丢弃了您的所有CSS(这也是很可能的)。 This is why you often receive email newsletters that are mostly images. 这就是为什么您经常收到大部分为图像的电子邮件新闻通讯的原因。

Use inline styles for everything to ensure that your HTML email displays the same on all clients. 对所有内容使用内联样式,以确保您的HTML电子邮件在所有客户端上都显示相同的样式

There is a good tool you can use for inlining your HTML content. 您可以使用一个很好的工具来内联HTML内容。 It is provided by mail-chimp (who i guess know a thing or two about emails) http://beaker.mailchimp.com/inline-css 它由mail-chimp提供(我猜他们对电子邮件了解一两件事) http://beaker.mailchimp.com/inline-css

It is always better to use inline styles rather then embedded css because some major email clients (such as Outlook 2007) do not support CSS in emails. 最好使用嵌入式样式而不是嵌入式CSS,因为某些主要的电子邮件客户端(例如Outlook 2007)不支持电子邮件中的CSS。

Gmail doesn't support embedded CSS. Gmail不支持嵌入式CSS。

One way to get around this issue is to convert your embedded CSS into inline using our CSS conversion tool in the "Developer Tools" dropdown in each test result. 解决此问题的一种方法是,在每个测试结果的“开发人员工具”下拉菜单中,使用我们的CSS转换工具将嵌入式CSS转换为内联。

There is another way of getting around the issue for things like font, font color and font size: Gmail converts your Body tag to a DIV. 解决字体,字体颜色和字体大小之类的问题的另一种方法是:Gmail将您的Body标签转换为DIV。 That can actually work to your advantage because you can use any inline CSS properties within your BODY that would otherwise be supported by a DIV. 这实际上可以为您带来好处,因为您可以在BODY中使用DIV支持的任何内联CSS属性。 It is important to know, however, that some clients do not support the BODY tag so you should also include the same declarations within your embedded CSS. 但是,重要的是要知道,某些客户端不支持BODY标记,因此您还应该在嵌入式CSS中包含相同的声明。 Also, keep in mind, you cant rely on BODY attributes like "bgcolor" because it is not supported within a DIV 另外,请记住,您不能依赖于BODY属性,例如“ bgcolor”,因为DIV不支持该属性。

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

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