简体   繁体   English

HTML 电子邮件链接颜色困境

[英]HTML email link color dilemma

I designed an HTML email and I am having the following issues: First my entire design is based on a blue color so any blue text will not be readable by the reader/user, text has to be white.我设计了一个 HTML 电子邮件,但遇到以下问题:首先,我的整个设计基于蓝色,因此读者/用户无法读取任何蓝色文本,文本必须为白色。 GMAIL automatically color phone numbers and links blue but the main problem is Microsoft Outlook OWA. GMAIL 自动将电话号码和链接着色为蓝色,但主要问题是 Microsoft Outlook OWA。

To fix the phone number and link coloring in GMAIL I did the following:为了修复 GMAIL 中的电话号码和链接颜色,我执行了以下操作:

<a style="color: #FFFFFF; 
   text-decoration: none" 
   href="#/">
       <span style="color: #FFFFFF; 
                    text- decoration: none">
           1800-000-0000
       </span>
</a>

This works perfectly for GMAIL and every where else BUT as I mentioned most of my client uses Outlook or MS OWA (Outlook Web Application).这对于 GMAIL 和其他所有地方都非常有效,但正如我提到的,我的大多数客户都使用 Outlook 或 MS OWA(Outlook Web 应用程序)。

OWA ignores the color I set in my inline style and makes the link default blue; OWA 忽略我在内联样式中设置的颜色,并将链接设为默认蓝色; this only happens when the email is previewed.这仅在预览电子邮件时发生。 If you actually open the email all the styles kicks in.如果您真的打开电子邮件,所有样式都会出现。

My dilemma is, what should I do?我的困境是,我该怎么办? I have already given up hope but this is my last resort.我已经放弃了希望,但这是我最后的手段。 Is there a way to override the link color for Outlook OWA?有没有办法覆盖 Outlook OWA 的链接颜色? I have used !IMPORTANT, the FONT tag, NESTING to the 5 degree.我使用了 !IMPORTANT,FONT 标签,NESTING 到 5 度。

The Problem here is not Outlook but OWA.这里的问题不是 Outlook,而是 OWA。

Here is a screenshot when I inspect the element in Chrome:这是我在 Chrome 中检查元素时的屏幕截图:

Google Chrome 开发者面板截图

And here is FF:这是FF:

在此处输入图片说明

Any ideas?有任何想法吗?

Please!请!

You'll find success by including the <font> declaration, which is deprecated in modern HTML, though some versions of OWA still respect it:您将通过包含<font>声明取得成功,该声明在现代 HTML 中已被弃用,但 OWA 的某些版本仍然尊重它:

<a style="color: #FFFFFF; text-decoration: none" href="#/">
  <span style="color: #FFFFFF; text-decoration: none">
    <font color="#FFFFFF">1800-000-0000</font>
  </span>
</a>

Outlook Web App (OWA) link colors change from inline styles. Outlook Web App (OWA) 链接颜色从内联样式更改。 I have spent a few hours trying to change/fix link colors in OWA where it strips away inline styles for email templates I am creating.我花了几个小时试图更改/修复 OWA 中的链接颜色,它去除了我正在创建的电子邮件模板的内联样式。 I tried various techniques with + tags with no success.我尝试了各种带有 + 标签的技术,但没有成功。 Finally found something that seems to work:终于找到了一些似乎有效的东西:

      <a href="http://www.somewebsite.com.au/" target="_blank" style="color:#FFFFFF;">White Link</a>

Changed it to:改为:

      <a href="http://www.somewebsite.com.au/" target="_blank" style="color:#FFFFF6;">White Link (almost)</a>

Seems fine so far.目前看来还好。

Further testing.进一步测试。 I put the slightly off color on the the <td style="color:#FFFFF6;"> then the correct color on the <a href="http://www.somewebsite.com.au/" target="_blank" style="color:#FFFFFF;">我在<td style="color:#FFFFF6;">然后在<a href="http://www.somewebsite.com.au/" target="_blank" style="color:#FFFFFF;">上添加了正确的颜色<a href="http://www.somewebsite.com.au/" target="_blank" style="color:#FFFFFF;">

Its a known bug with Outlook that if an anchor tag does not contain a valid URL, then the styling of said tag will be ignored. Outlook 的一个已知错误是,如果锚标记不包含有效的 URL,则该标记的样式将被忽略。

The tendancy to add !important will also work against you in this case because Outlook will completely ignore any tags suffixed with !important.在这种情况下,添加 !important 的倾向也会对您不利,因为 Outlook 将完全忽略任何以 !important 为后缀的标签。

Put a URL on your anchor tag, or wrap the text in a span tag inside of the anchor and put your styling there.在锚标签上放置一个 URL,或者将文本包裹在锚内的 span 标签中,并将您的样式放在那里。

I have been able to fix this by putting a table inside the a tag.我已经能够通过在a标签内放置一个表格来解决这个问题。

<a href="">
    <table>
        <tr>
            <td style="color: #FFFFFF">Link text here</td>
        </tr>
    </table>
</a>

Figures.图。 Just when we've gotten used to not being able to use the cool new email tricks because Outlook doesn't support them, Microsoft throws OWA at us, with a whole slew of new bugs.正当我们因为 Outlook 不支持而习惯了无法使用很酷的新电子邮件技巧时,Microsoft 向我们抛出了 OWA,其中包含大量新错误。

We've gotten around its awful link styling by applying a display:inline-block to the link.我们通过对链接应用display:inline-block来解决其糟糕的链接样式。 This at least gets rid of the underline.这至少摆脱了下划线。 I have no idea why.我不知道为什么。

We ran into another bug when trying to style our links the same color as the parent element.在尝试将链接的样式设置为与父元素相同的颜色时,我们遇到了另一个错误。 For some reason, making the parent element's color different fixed it.出于某种原因,使父元素的颜色不同可以修复它。 Changing it by one character up or down usually gives you a pretty close color.向上或向下改变一个字符通常会给你一个非常接近的颜色。

<td style="color:#CCCCCD">
<a href="http://mylink" style="display:inline-block; color:#CCCCCC">Link</a>
</td>

I used the following and it worked fine in Outlook 2007, 2010, 2013, and Outlook.com.我使用了以下内容,它在 Outlook 2007、2010、2013 和 Outlook.com 中运行良好。 I will check with OWA soon.我会尽快与 OWA 核实。

#outlookLink {text-decoration: none; color: #ffffff !important}
<a href="" id="outlookLink" name="Anchor" style="text-decoration: none; color: #ffffff !important;">Your text and link here.</a>
<a href="#" style="color: #FFF;">
  <strong style="color: #FFF; font-weight: normal;">Example Link</strong>
</a>

it worked for me!它对我有用! Make sure to use <strong> , I tried it with other tags, but that didn't work.确保使用<strong> ,我尝试使用其他标签,但没有用。

I have also noticed that for OWA the order of items in the style= property might be relevant.我还注意到,对于 OWA, style=属性中的项目顺序可能是相关的。 I've seen cases when using:我见过使用时的情况:

<a href="/some_url" style="text-decoration: none; color: inherit;">...</a>

Would cause OWA to strip the color attribute (but leave `text-decoration), but reversing the order, eg:会导致 OWA 去除color属性(但保留`text-decoration),但顺序颠倒,例如:

<a href="/some_url" style="color: inherit; text-decoration: none;">...</a>

Would make OWA preserve both.将使 OWA 保留两者。 I can't see any sense in this, but this is how it is...我看不出有任何意义,但这就是它的方式......

I've also see that the context of a tag can influence this style-stripping: The stripping I mentioned above is triggered when the a tag is preceded by a h2 tag, but removing that h2 also prevents OWA from stripping the tag (I haven't investigated when or why this happens exactly, though, just wanted to point out that context can be relevant here as well).我还看到标签的上下文会影响这种样式剥离:当 a 标签前面是h2标签时会触发我上面提到的剥离,但是删除h2也会阻止 OWA 剥离标签(我没有没有调查这种情况究竟何时或为什么发生,只是想指出上下文在这里也可能相关)。

I realize that none of this is a direct answer to the original question, but I imagine it will be helpful for others who come here with a similar question.我意识到这些都不是原始问题的直接答案,但我想这对带着类似问题来到这里的其他人会有所帮助。

OWA is actually stripping all the styles of the a-tag, including that of the span-tag you included. OWA 实际上正在剥离 a-tag 的所有样式,包括您包含的 span-tag 的样式。 You can add styles in the head part, but again, OWA is ignoring this for hyperlinks.您可以在头部部分添加样式,但同样,OWA 忽略了超链接的这一点。 I added a style for a, a:link, a:visited in the head, the same color as in the a-tag and the including span-tag.我在头部添加了 a、a:link、a:visited 的样式,颜色与 a-tag 和包含 span-tag 中的颜色相同。 The result?结果? My linktext is colored but the underlining is still the default blue.我的链接文本是彩色的,但下划线仍然是默认的蓝色。 The clue: there's no clue for me.线索:我没有线索。

When sending html emails the best practice is to stick to old HTML3 and HTML4.发送 html 电子邮件时,最佳做法是坚持使用旧的 HTML3 和 HTML4。 Email clients do not play well with CSS2 and up.电子邮件客户端在 CSS2 及更高版本上运行不佳。 Inline CSS work much better.内联 CSS 效果更好。

Instead of:代替:

<a style="color: #FFFFFF; text-decoration: none" href="#/">
 <span style="color: #FFFFFF; text- decoration: none">1800-000-0000</span>
</a> 

By the way, you have syntax errors in this line, after each css declaration you need a ;顺便说一句,你在这一行有语法错误,在每个 css 声明之后你需要一个 ;

Corrected:更正:

<a style="color: #FFFFFF; text-decoration: none;" href="#">
  <span style="color: #FFFFFF; text- decoration: none;">1800-000-0000</span>
</a> 

Try this:试试这个:

<a color="#FFFFFF" text-decoration="none" href="#">
  1800-000-0000
</a>

Do not forget to specify the HTML version on the DOCTYPE.不要忘记在 DOCTYPE 上指定 HTML 版本。

I've found myself working in both sides of this situation.我发现自己在这两种情况下都在工作。 I worked on a web based email client using PHP with IMAP, I had to strip HTML emails of a lot of things because they'd break not only the layout of the app but also the intended behavior of buttons and forms.我在一个使用 PHP 和 IMAP 的基于 Web 的电子邮件客户端上工作,我不得不从 HTML 电子邮件中删除很多东西,因为它们不仅会破坏应用程序的布局,还会破坏按钮和表单的预期行为。 How?如何? you might ask.你可能会问。 With a desktop email client this probably wouldn't be a problem but with a web based email client loading external css/js files can result into a very large array of potential pitfalls and nasty bugs.对于桌面电子邮件客户端,这可能不是问题,但是对于基于 Web 的电子邮件客户端,加载外部 css/js 文件可能会导致大量潜在的陷阱和令人讨厌的错误。

On another occasion I was working on wedding invitations sent over HTMl emails, The amount of inline css we had to do was ridiculous.在另一个场合,我正在处理通过 HTMl 电子邮件发送的婚礼请柬,我们必须做的内联 css 的数量是荒谬的。 To make it work on you have to use mostly HTML3 and maybe a bit of HTML4 but not too much.为了让它发挥作用,你必须主要使用 HTML3,也许还有一点 HTML4,但不要太多。

I recommend you to experiment with tables and deprecated HTML3 inline css.我建议您尝试使用表格和已弃用的 HTML3 内联 css。


Try adding a class my-link to each link in question and the following CSS in your style tag:尝试在每个有问题的链接中添加一个类my-link并在您的style标签中添加以下 CSS:

.my-link a,
a[x-apple-data-detectors] {
  color:inherit !important;
  text-decoration: underline !important;
}

That usually covers things for me.这通常涵盖了我的事情。 If that fails, there is a heavier version of this code here:如果失败,这里有一个更重的代码版本:

.my-link a,
a[x-apple-data-detectors] {
    color: inherit !important;
    text-decoration: none !important;
    font-size: inherit !important;
    font-family: inherit !important;
    font-weight: inherit !important;
    line-height: inherit !important;
}

source 来源

I saw this thread and tried the options above.我看到了这个线程并尝试了上面的选项。 The TD hack worked with changing the hex code, but I just stumbled upon a nice solution if anyone would like to try: TD hack 用于更改十六进制代码,但如果有人想尝试,我只是偶然发现了一个不错的解决方案:

<div style="text-decoration: none;">
<a href="LINK" style="display: inline-block; color: #878f93; text-decoration: none;">LINK TEXT</a>
</div>

Setting the DIV to text-decoration NONE was supported by OWA. OWA 支持将 DIV 设置为 text-decoration NONE。 I personally was asked to remove the underline, so for my case it's perfect.我个人被要求删除下划线,所以对我来说这是完美的。

I hope people find this useful.我希望人们觉得这很有用。 Thanks for everyone who added their solutions as well.感谢所有添加解决方案的人。

This question is still relevant as of today 21-12-2017.截至今天 21-12-2017,这个问题仍然相关。 I had no problem with my code in Outlook, Gmail but not in Outlook Web App.我在 Outlook、Gmail 中的代码没有问题,但在 Outlook Web App 中没有问题。 I had to use this outdated tag to solve it.我不得不使用这个过时的标签来解决它。

<a class="app-link" style="font-size:14px; color:#ff6600 !important; text-decoration:underline;" href="https://somesite/something/"><font color="#ff6600 !important;"> Gå til app</font></a>

It was weird that style within hyperlink will NOT work for Outlook Web App(OWA), therefor, adding <font color="#ff6600 !important;"> worked!奇怪的是,超链接中的样式<font color="#ff6600 !important;">用于 Outlook Web App(OWA),因此,添加<font color="#ff6600 !important;">起作用了! Strange but this is how Microsoft wants to tease us!奇怪,但这就是微软想要取笑我们的方式!

** **

PSEUDO CSS SUPPORTED (2007, 2010, 2016, 2017 and others)支持伪 CSS(2007、2010、2016、2017 等)

It is like a hack because it doesn't support.它就像一个黑客,因为它不支持。

<a href="#" target="_blank" style="font-size:20px;">
   <strong style="color:#ffffff;">@Model.TelephoneTextHtml</strong>
</a>

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

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