简体   繁体   English

html电子邮件的速记CSS可能吗?

[英]Shorthand CSS on html emails possible?

I am wondering if shorthand CSS coding is allowed for HTML Emails. 我想知道HTML电子邮件是否允许使用简写CSS编码。

I know the CSS allowed is very limited but I know padding for example is allowed but would this be allowed: 我知道允许的CSS非常有限,但我知道允许填充,但允许这样做:

padding:0 4px 0 6px;

The CSS that is allowed in an email is what the receiving email client understands. 电子邮件中允许的CSS是接收电子邮件客户端理解的内容。 There are many different email clients. 有许多不同的电子邮件客户端。 Not all of them even render HTML email (though virtually all do these days), but even where they do render HTML, their rendering engines will all be different from one another, in the same way as web browsers. 并非所有人都提供HTML电子邮件(尽管几乎所有人都这么做),但即使他们确实渲染HTML,他们的渲染引擎也会以与Web浏览器相同的方式彼此不同。 But unlike web browsers, people don't always change their email client if they're not happy with the way it renders. 但与网络浏览器不同的是,如果人们对呈现的方式不满意,人们并不总是更改他们的电子邮件客户端。

So you should expect your email to be read using virtually any kind of email program, including ones which don't render HTML at all, and those which render it, but using an IE4-vintage rendering engine. 因此,您应该期望使用几乎任何类型的电子邮件程序来阅读您的电子邮件,包括根本不呈现HTML的电子邮件程序,以及使用IE4复古渲染引擎呈现它的那些电子邮件程序。

That said, I would expect virtually all email clients to correctly interpret the CSS padding style. 也就是说,我希望几乎所有的电子邮件客户端都能正确解释CSS padding样式。

You may get some with quirks-mode box models, which will cause your box sizes and positions to be wrong, but they should still interpret the padding correctly within their own set of rules. 你可能会得到一些带有怪癖模式的盒子模型,这会导致你的盒子大小和位置错误,但他们仍然应该在他们自己的规则集中正确解释padding

One thing I would say is that you should ensure all your CSS code is embedded in the HTML. 我要说的一件事是你应该确保所有CSS代码都嵌入在HTML中。 Put a big <style> tag at the top of your document, rather than a <link> tag with an external reference. 在文档的顶部放置一个大的<style>标记,而不是带有外部引用的<link>标记。 The reason for this is that 1) some users may view your email when they're offline, in which case they won't be able to load an external stylesheet, and 2) some email clients may be set to block loading external files from within an email for security reasons, even if the user is online. 原因是1)一些用户可能在他们离线时查看您的电子邮件,在这种情况下他们将无法加载外部样式表,2)某些电子邮件客户端可能被设置为阻止加载外部文件出于安全原因,即使用户在线,也要在电子邮件中。 If your styles are all included in the main body of the email, this won't be a problem. 如果您的样式都包含在电子邮件的正文中,这将不会有问题。 (you may still have the same issue with graphics, but that's a whole different topic of discussion) (你可能仍然有相同的图形问题,但这是一个完全不同的讨论主题)

In case this is still of interest I have been looking into this lately. 如果这仍然是我感兴趣的话,我最近一直在研究这个问题。 Some mass mail company clearly state that some applications like font (at least) are not rendered well on some email clients. 一些大型邮件公司明确表示某些应用程序(如字体)(至少)在某些电子邮件客户端上的呈现效果不佳。

http://www.campaignmonitor.com/resources/will-it-work/guidelines/ http://www.campaignmonitor.com/resources/will-it-work/guidelines/

Actually after reviewing a few email sources of templates (Mailchimp, Campaign Monitor, etc) they all consistently avoid them so my conclusion so far is been to do so as well. 实际上,在审查了一些模板的电子邮件来源(Mailchimp,Campaign Monitor等)之后,他们都一直避免使用它们,所以到目前为止我的结论也是如此。

In any case more important than shorthand or not is the fact that most CSS styles need to get "inline" of elements as many (Gmail included) ignores them if defined on the head. 在任何情况下,比简写更重要的事实是,大多数CSS样式需要获得元素的“内联”(如果包括Gmail),如果在头部定义则忽略它们。

As a simple solution I tend to use basic styles on the body element and on a containing table surrounding the content (as body styles also get removed by some clients). 作为一个简单的解决方案,我倾向于在body元素和围绕内容的包含表上使用基本样式(因为某些客户端也会删除正文样式)。

在最简单的形式中,您可以为每个元素设置样式,如下所示:

<p style="padding:0 4px 0 6px;">your contents</p>

Yes. 是。

And, as with any "webpage", what the user actually sees is completely up to the "browser" (or HTML-capable email client). 而且,与任何“网页”一样,用户实际看到的内容完全取决于“浏览器”(或支持HTML的电子邮件客户端)。

You could have simply tried it to find out. 你可以简单地尝试一下来找出答案。

Also, I recommend not being obnoxious by splashing graphics and colours all over emails. 此外,我建议不要通过电子邮件中的图形和颜色来表示讨厌 :( :(

I have never had a problem doing 'shorthand' like that, so long as all of the values are provided. 只要提供了所有的值,我就不会像这样做“速记”。 Technically, padding:0px 4px; 技术上, padding:0px 4px; should work such that top & bottom are 0, and left & right are 4, but not all email clients will honor that (I'm talking to you, Outlook 2007/2010!) so you need to include all four for margin, padding, border etc. 应该工作,顶部和底部是0,左和右是4,但不是所有的电子邮件客户端都会尊重(我正在和你说话,Outlook 2007/2010!)所以你需要包括所有四个边距,填充,边境等

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

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