如何在内联 CSS 中编写 a:visited?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9162362/
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
How to write a:visited in inline CSS?
提问by Atara
Related Topic: How to write a:hover in inline CSS?
I need to create an HTML Email News Letters. All styles should be inline. (According to – http://www.campaignmonitor.com/css/Not all email clients recognize STYLE tag with in the HEAD tag. but they all prefer inline styles.)
我需要创建一个 HTML 电子邮件新闻快报。所有样式都应该是内联的。(根据 - http://www.campaignmonitor.com/css/并非所有电子邮件客户端都能识别 HEAD 标签中的 STYLE 标签。但他们都更喜欢内联样式。)
My Problem:The designer wants a dark background color + white links, so I use -
我的问题:设计师想要深色背景色 + 白色链接,所以我使用 -
<a href="http://www.mySite.com" target="_blank">
<span style="color: #ffffff;" >ici</span>
</a>
but the default "visited color" is dark.
但默认的“访问颜色”是深色的。
Is there another way to change the "visited color" ?
还有另一种方法可以更改“访问的颜色”吗?
Thanks,
谢谢,
Atara.
阿塔拉。
P.S. I also tried the decrypted BODY link, vlink attributes. did not work.
PS我也试过解密后的BODY链接,vlink属性。不工作。
回答by kibibu
First off, good luck! HTML email is stuck firmly at 1996 tech levels.
首先祝你好运!HTML 电子邮件牢牢地停留在 1996 年的技术水平上。
One thing to attempt if you don't actually needa separate "visited" colour is to add an !important on the span.
如果您实际上不需要单独的“已访问”颜色,则可以尝试的一件事是在跨度上添加 !important 。
For example, your mail client mayhave something like this in their style sheet:
例如,您的邮件客户端的样式表中可能包含以下内容:
a:visited * { color: #000 !important; }
In which case that will override your inline style.
在这种情况下,这将覆盖您的内联样式。
So, try changing your span to:
因此,尝试将您的跨度更改为:
<a href="http://www.example.com" target="_blank">
<span style="color: #ffffff !important;" >ici</span>
</a>
to override it back again.
再次覆盖它。
A quick test in Chrome shows that the a:visited * { ... !important}
does override the inline style, but adding the !important
back to the span works fine.
Chrome 中的快速测试表明,a:visited * { ... !important}
确实覆盖了内联样式,但将!important
back添加到 span 效果很好。
2017 Update
2017年更新
The CampaignMonitor CSS guide now seems to recommend using a <style>
element in the head, rather than inlining all styles. Based on other answers this seems to provide the best compatibility with recent version of Outlook.
CampaignMonitor CSS 指南现在似乎建议<style>
在头部使用元素,而不是内联所有样式。根据其他答案,这似乎提供了与最新版本 Outlook 的最佳兼容性。
回答by Samuel
This is pretty old thread but thought it would be useful to somebody. Nothing else worked for me in outlook 2013 except using the plain old
这是一个很旧的线程,但认为它对某人有用。除了使用普通的旧版本外,在 Outlook 2013 中没有其他方法对我有用
<style>a:visited{color:white !important}</style>
within the body
在体内
回答by Barry Michael Doyle
Why not try setting the style
attribute inside the <a>
tag and removing the <span>
altogether?
为什么不尝试style
在<a>
标签内设置属性并<span>
完全删除?
Doing that inline should overwrite the :visited
property.
执行内联操作应该会覆盖该:visited
属性。
Like this:
像这样:
<a href="http://www.example.com" target="_blank" style="color: #ffffff !important;" >
ici
</a>
Note:And just to be safe you can add the !important
property in there to further back it up.
注意:为了安全起见,您可以!important
在其中添加该属性以进一步备份它。
I think this is the best practice and the cleanest way to do this.
我认为这是最好的做法,也是最干净的方法。
回答by Chocoliver
I tried all that ideas described here in 2016 (with Outlook 2010 and up), none of them worked for me. But I had success using this solution: https://jamesnorthard.com/outlook-changing-visited-link-color-in-email/
我在 2016 年尝试了这里描述的所有想法(使用 Outlook 2010 及更高版本),但没有一个对我有用。但是我使用这个解决方案取得了成功:https: //jamesnorthard.com/outlook-changed-visited-link-color-in-email/
He uses the strong tag inside the anchor tag (code from his blog post):
<a href="#" style="color:#333399;"><strong style="font-weight:normal;">My Link</strong></a>
他在锚标签中使用了强标签(代码来自他的博文):
<a href="#" style="color:#333399;"><strong style="font-weight:normal;">My Link</strong></a>
It even fixes the problem of a changing link color when forwarding an email with Gmail.
它甚至解决了使用 Gmail 转发电子邮件时链接颜色变化的问题。
Hope that helps anyone else!
希望对其他人有帮助!
回答by Chocoliver
a quick and dirty solution : add vlink = "yourcolor"in the bodyof your HTML Email News Letter (works with !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd")
一个快速而肮脏的解决方案:在HTML 电子邮件新闻信的正文中添加vlink = "yourcolor"(适用于 !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www. w3.org/TR/html4/loose.dtd")