有没有办法在 html 电子邮件中的“a:hover”上的 href 链接上设置内联样式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2911369/
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-29 03:11:54  来源:igfitidea点击:

Is there a way to set an inline style on an href link on "a:hover" in a html email?

htmlcssemail

提问by Pierre Watelet

The question is to know if there is a way to build an HTML email with inline style (no CSS file, nor <style>tags) with the href links that react with the mouse passing over them : just to be able to change the color font.

问题是要知道是否有一种方法可以构建带有内联样式(没有 CSS 文件,也没有<style>标签)的 HTML 电子邮件,其 href 链接会随着鼠标经过它们而做出反应:只是为了能够更改颜色字体。

So, no JS, no script, no <style>, just <a href="http://www.dot.com style="....">link</a>

所以,没有 JS,没有脚本,没有<style>,只是<a href="http://www.dot.com style="....">link</a>

采纳答案by Quentin

No.

不。

You can't apply pesudo-classes (or anything else that appears in a selector) via the style attribute.

您不能通过 style 属性应用伪类(或出现在选择器中的任何其他内容)。

回答by Kyle

The normal HTML way for inline styling is:

内联样式的正常 HTML 方式是:

<a href="url" style="color:#cfe7fe";">Click me!</a>

But I am not sure how reliable that is in email templates.

但我不确定电子邮件模板中的可靠性如何。

You could always try: (Although deprecated)

您可以随时尝试:(虽然已弃用)

<font color="blue"> <a href="url">Click me!</a> </font>

Hope it helps.

希望能帮助到你。

Edit:For inline hover try using:

编辑:对于内联悬停尝试使用:

onmouseover="this.style.color='blue';" 
onmouseout="this.style.color='black';"

But again I am not sure on email support for this.

但我再次不确定是否对此提供电子邮件支持。

回答by Pekka

Some E-Mail clients support styletags, and thus the defining of pseudo-selectors. According to this list:

一些电子邮件客户端支持style标签,从而定义伪选择器。根据这份清单:

Guide to CSS support in E-Mail clients

电子邮件客户端中的 CSS 支持指南

:hoveris supported by a good number of clients.

:hover得到了大量客户的支持。

You should be able to slip a <style>tag into the body if necessary. That's not valid, but rich E-Mails are such a minefield that that is going to hardly matter.

<style>如有必要,您应该能够将标签滑入身体。这是无效的,但丰富的电子邮件是一个雷区,这几乎无关紧要。

:hoveris your only chance I think. It's not possible to define pseudo-selectors inline, and JavaScript is out because it's going to be blocked by most (or all?) clients.

:hover我认为是你唯一的机会。内联定义伪选择器是不可能的,而且 JavaScript 已经过时了,因为它会被大多数(或所有?)客户端阻止。

回答by Michael

You can, however, you will not be able to change the color of the underline. You can wrap the the link text in a div and then wrap the div in a link, like this:

但是,您将无法更改下划线的颜色。您可以将链接文本包装在 div 中,然后将 div 包装在链接中,如下所示:

<a href="http://www.google.com"><div style="margin: 0px;padding: 20px 50px;font-size: 50px; color: red;">GOOGLE</div></a>

The word "GOOGLE" will appear red, but with a blue underline. So that does not exactly solve your problem, I don't think.

“GOOGLE”一词将显示为红色,但带有蓝色下划线。所以这并不能完全解决你的问题,我不认为。