gpt4 book ai didi

javascript - :hover pseudoclass selector in email for gmail

转载 作者:数据小太阳 更新时间:2023-10-29 04:42:22 25 4
gpt4 key购买 nike

我正在从我的 php 发送一些邮件脚本。

它的结构如下:

<style type="text/css">
.elements{
/*its CSS*/
}
.elements:hover{
/* Hoverd CSS changes background and color*/
}
</style>
<center>
Actual Mail Body <a class="elements" href="URL">Element</a>
<center>

这在除 gmail 以外的所有邮件客户端中都可以正常工作.这么快SO搜索将我带到:HTML formatted email not showing up at all in Gmail but is in other mail clients

然后我才知道gmail不支持 <style>但支持 inline-style .

所以我尝试了这个:

<center>
Actual Mail Body <a class="elements" href="URL" style="it's style here">Element</a>
<center>

但现在我的问题是:hover伪类无法转换为 inline-style , 所以我试着用 JavaScript 来模仿它作为:

<center>
Actual Mail Body <a class="elements" href="URL"
OnMouseOver="this.style.background='#ddeeff';this.style['color']='#555555';"
onmouseout="back-to-original-css">Element</a>
<center>

但这对我没有帮助。

那么有什么方法可以使:hover伪类工作在 gmail邮件客户端?

我也不认为这是不可能的(看看你的g+'s账户中的gmail邮件。他们可以发送这样的邮件。)

欢迎任何想法、想法和建议,在此先感谢。

最佳答案

关于这个主题有很多争议,但这是我发现的。 准备一堵文字墙。看来您可以使用解决方法来制作 <style>工作,如所述here .

以下是实际报价:

Gmail strips class and id attributes from all elements but leaves some other attributes intact: style, title, lang, width, height, alt, href.

Since href and alt are not technically legal attributes for divs I decided not to use them even though you could if you wanted to. A prime candidate would be title – however title comes with one side-effect – when the user hovers the cursor over the element, the title would be visible.

I chose the lang attribute because it is a universal attribute (valid for all elements) that is not visible when hovered over. Naturally we’re not using this attribute for its intended purpose – but there’s a technical exception in the HTML specifications that allow us to use it this way. By pre-pending the attribute value with an “x-”, this signifies that the lang attribute is not meant to be meaningful to the client and as far as I know, no email client currently processes the lang attribute anyways.

Breakdown

Here’s a total breakdown of all the styles I’ve tried and found working in Gmail:

The following works in Gmail:
* E[foo]
* E[foo="bar"]
* E[foo~="bar"]
* E[foo^="bar"]
* E[foo*="bar"]
* E[foo$="bar"]
* E:hover
* E:link
* E:visited
* E:active

E F
E > F
E + F
E ~ F

Gmail 如何处理样式标签中的 CSS(在电子邮件中)的摘要。

.divbox {..}  //Allowed but pointless - Gmail strips class attributes from elements
#divbox {..} //Allowed but pointless - Gmail strips id attributes from elements

[class~="divbox"] {...} //Removed by Gmail
* [class~="divbox"] {...} //Allowed but pointless - No class attributes

div {...} //Allowed but too generic to be useful
div:hover {...} //Removed by gmail. No pseudo class support? Not so fast!
* div:hover {...} //Allowed! Interesting…

* [lang~="x-divbox"] {...} //Allowed! Now we’re talking

* [lang~="x-divbox"]:hover {...} //Allowed! Magic! :)

免责声明:这篇文章不是我写的,我不相信它。

编辑:

我测试过它在 gmail 和 outlook (hotmail) 上都有效。

我使用的代码:

<html>
<head>
<style>
* [title="divbox"]:hover{
background-color: green !important;
color: white;
}

.blinking:hover{
background-color: green !important;
color: white;
}
</style>
</head>
<body>
<div class="blinking" title="divbox" style="padding:10px;width:100px;height:40px;
background-color:#eeeeee;">Divbox Content</div>
</body>
</html>

附注:blinking类适用于 hotmail,因为它不显示 gmail 解决方法。

关于javascript - :hover pseudoclass selector in email for gmail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25812613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com