我可以在 HTML 文件的正文中放置一个 <style>...</style> 标签以通过电子邮件发送吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/225828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:34:08  来源:igfitidea点击:

Can I put a <style>...</style> tag within the body of a HTML file to send in email?

htmlcssemail

提问by Manu

Since a lot of email clients ignore the HEAD tag, can I embed an inline stylesheet in the body?

由于许多电子邮件客户端忽略 HEAD 标记,我可以在正文中嵌入内联样式表吗?

回答by cllpse

The short answer is no. Gmail strips the tag and it's content.

最简洁的答案是不。Gmail 会去除标签及其内容。

Hotmail, Yahoo! Mail and Windows Live Mail does not strip style-tags in the body-element.

Hotmail,雅虎!邮件和 Windows Live Mail 不会在正文元素中去除样式标签。

But take a look at "The Ultimate Guide to CSS" for HTML emailover at Campaign Monitor.

但是在 Campaign Monitor 上查看 HTML 电子邮件的“CSS 终极指南”

回答by Andy Ford

You might want to check out the free html email templates that CampaignMonitor and MailChimp (EDIT:and Ink by Zurb) provide:

您可能想查看 CampaignMonitor 和 MailChimp(编辑:Zurb 的 Ink)提供的免费 html 电子邮件模板:

http://www.campaignmonitor.com/templates/

http://www.campaignmonitor.com/templates/

http://www.mailchimp.com/resources/templates/

http://www.mailchimp.com/resources/templates/

http://zurb.com/ink/

http://zurb.com/ink/

There's an updated version of Campaign Monitor's helpful guide here: http://www.campaignmonitor.com/css/

此处提供了 Campaign Monitor 有用指南的更新版本:http: //www.campaignmonitor.com/css/

Unfortunately, the most reliable HTML to use in emails is totally stone age

不幸的是,在电子邮件中使用的最可靠的 HTML 完全是石器时代

EDIT:Ink has an "inliner" tool that takes the contents of styletags and inlines them onto the appropriate elements: http://zurb.com/ink/inliner.php

编辑:Ink 有一个“内联”工具,可以将style标签的内容内联到适当的元素上:http: //zurb.com/ink/inliner.php

回答by Glen Lipka

Creating an HTML email that works in every email client is hard. I spent several months refining a good looking template.

创建适用于每个电子邮件客户端的 HTML 电子邮件是很困难的。我花了几个月的时间改进了一个好看的模板。

http://commadot.com/the-holy-mail/- original blog with my findings.

http://commadot.com/the-holy-mail/- 包含我的发现的原始博客。

http://commadot.com/email-best-practices/- latest greatest.

http://commadot.com/email-best-practices/- 最新最好的。

Specific answer to your question: Gmail will be ok with style=""but not with a <style>block.

您问题的具体答案:Gmail 可以使用,style=""但不能使用<style>块。

回答by Chris Villa

Most gmail clients now support embedded CSS as of September 2016, so it should be safe to do.

截至 2016 年 9 月,大多数 gmail 客户端现在都支持嵌入式 CSS,因此应该是安全的。

https://litmus.com/blog/gmail-to-support-responsive-email-design

https://litmus.com/blog/gmail-to-support-responsive-email-design

回答by teebot

Yes you can. However you have to keep in mind that few email clients respect css standards. Just stick to basic css properties like marginand padding, etc., and it should all be fine.

是的你可以。但是,您必须记住,很少有电子邮件客户端遵守 css 标准。只需坚持基本的 css 属性,如marginandpadding等,一切都应该没问题。

Also you can style your html elements inline (<div style="">) though it's not an elegant solution.

您也可以内联 ( <div style="">) 设置html 元素的样式,尽管这不是一个优雅的解决方案。