如何禁用Thymeleaf对邮箱字段的自动超链接格式化?
问题:Thymeleaf模板中邮箱字段被自动添加超链接样式,内联样式无效
我在用Thymeleaf制作模板时碰到个问题:当creatorName字段是邮箱格式(比如dataautomation@gmail.com)时,它会被自动加上蓝色下划线的超链接样式,但我需要它和其他普通文本一样以白色渲染。
我尝试给包裹字段的<span>添加带!important标记的内联样式,但完全没效果:
<p>Ticket Creator: <span th:text="${creatorName}" style="color: white !important; -webkit-text-fill-color: white; text-decoration: none !important; pointer-events: none; cursor: default;"></span></p>
解决方法
排查后发现,这个超链接样式并非Thymeleaf添加,是Outlook自动生成的。添加针对Outlook的特定样式即可解决:
在模板的<head>中插入Outlook条件样式块:
<!--[if mso]> <style type="text/css"> #outlook a { padding: 0; color: white !important; text-decoration: none !important; } </style> <![endif]-->
这样就能强制覆盖Outlook给邮箱自动添加的超链接样式,让邮箱文本保持白色、无下划线,和其他普通文本样式一致。
内容的提问来源于stack exchange,提问作者Garrett Baltz
相关产品推荐
相关产品推荐

