简体   繁体   English

HTML电子邮件中的CSS类和@media规则

[英]css classes and @media rule within HTML emails

I have a content table(Scores table of my users) that is sent out automatically via email each in every predetermined period of time. 我有一个内容表(我的用户的得分表),每个预定的时间段内都会通过电子邮件自动发送。

The html used to have static table sizes and other measurements definitions in pixels, instead of in percents. html曾经有静态表大小和其他测量定义(以像素为单位),而不是百分比。

everything seemed fine on my iPhone, and also on chrome web browser, but went totally out of proportion on Android devices. 我的iPhone和Chrome网页浏览器上的一切似乎都很好,但在Android设备上完全不成比例。

I decided to convert in to a responsive layout, replacing those with percents. 我决定转换为响应式布局,用百分比代替。 This seems to have solved my problem, but now, due to the width difference between PC and mobile devices width \\ height ratio, I need to determine a different width for the scores table to a PC screen, and a mobile \\ tablet screen. 这似乎已经解决了我的问题,但现在,由于PC和移动设备宽度\\高度比之间的宽度差异,我需要确定分数表到PC屏幕和移动\\平板电脑屏幕的不同宽度。

I know that this can be done by using the @media rule, but the problem is that this feature of CSS can only be used within a style sheet, and not in an inline formatted CSS(within HTML). 我知道这可以通过使用@media规则来完成,但问题是CSS的这个功能只能在样式表中使用,而不能在内联格式的CSS(在HTML中)中使用。 And as you probably know, most email clients don't allow CSS style sheets(classes, CSS selectors) within HTML emails. 您可能知道,大多数电子邮件客户端都不允许HTML电子邮件中的CSS样式表(类,CSS选择器)。

What would you advice to do in such a situation?. 在这种情况下你会建议做什么?

Any assistance is much appreciated. 非常感谢任何帮助。

most email clients don't allow CSS style sheets(classes, CSS selectors) within HTML emails 大多数电子邮件客户端不允许HTML电子邮件中的CSS样式表(类,CSS选择器)

Not linked style sheets, but they allow you to place styles within style tags in the head . 未链接样式表,但他们让你中刊登的样式style中的标签head Yes, some email clients strip out those styles, but that's no reason not to use them. 是的,一些电子邮件客户端剥离了这些样式,但没有理由不使用它们。 Plenty of email clients also support @media rules these days. 如今,大量的电子邮件客户端也支持@media规则。 There is a lot of good advice about what is and isn't supported in the various email clients here . 关于此处各种电子邮件客户端支持和不支持的内容,有很多好的建议。 (That site also has a ton of well tested and nice looking email templates.) (该网站还有大量经过良好测试和漂亮的电子邮件模板。)

Because some email clients don't support styles in the head of the document, the safest approach is to add inline styles. 由于某些电子邮件客户端不支持文档头部的样式,因此最安全的方法是添加内联样式。 However, this should't stop you from placing styles in the head section—such as @media rules—for those clients that can handle them. 但是,这不应该阻止您在头部区域中放置样式 - 例如@media rules - 以便那些可以处理它们的客户端。

Just to add on to what ralph said... 只是为了补充ralph所说的......

As of last year Gmail became the most popular email client, and they strip the entire section out of an email. 截至去年,Gmail成为最受欢迎的电子邮件客户端,他们从电子邮件中删除整个部分。 So it's extremely important to use inline. 所以使用内联非常重要。

this is a pretty good resource for when you are targeting different email clients http://www.campaignmonitor.com/css/ 当您针对不同的电子邮件客户端时,这是一个非常好的资源http://www.campaignmonitor.com/css/

these are some helpful hacks i include in every head-style section 这些都是我在每个头型部分都包含的一些有用的黑客

<style>
/* Force Outlook to provide a "view in browser" button. */
body{ width:100% !important; height:100% !important; margin:0; padding:0; background-color: #f8f3eb;}
.ReadMsgBody{width:100%;} 
.ExternalClass{width:100%;} /* Force Hotmail to display emails at full width */
/* Reset Styles */
body{-webkit-text-size-adjust:none; -ms-text-size-adjust:none;} /* Prevent Webkit and Windows Mobile platforms from changing default font sizes. */
</style>

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

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