在iPhone上查看电话号码时,是否有办法删除默认的蓝色超链接颜色?像一个特定的移动Safari标签或CSS添加?

我只在数字的地方有这个:

<p id="phone-text">Call us on <strong>+44 (0)20 7194 8000</strong></p>

这里没有超链接,但iPhone仍然将这个文本数字显示为超链接。我在我的一些网站上有这个渲染问题,但不明白为什么会发生这种情况。

我确实读过这篇文章:

移动HTML渲染数字

但这是唯一可行的解决方案吗?


当前回答

a[href^=tel]{
    color:inherit;
    text-decoration: inherit;
    font-size:inherit;
    font-style:inherit;
    font-weight:inherit;

其他回答

我一直在

1.

    <a href="tel:5551231234">

2.

    <meta name="format-detection" content="telephone=no">

试着让同样的代码适用于台式机和iPhone。问题在于,如果你使用了第一个选项,并从桌面浏览器中点击它,它会给出一个错误消息,如果使用了第二个选项,它会禁用iPhone iOS5上的标签呼叫功能。

所以我试了又试,结果iPhone把电话号码当作一种特殊类型的链接,可以用CSS格式化。我把数字包装在一个地址标签(它将与任何其他HTML标签,只是尽量避免< >标签),并在CSS样式为

.myDiv address a {color:#FFF; font-style: normal; text-decoration:none;}

在桌面浏览器中显示一个纯文本,在Safari移动浏览器中显示一个链接,并在选项卡上弹出Call/Cancel窗口,没有默认的蓝色和下划线。

只是要注意应用于数字的css规则,特别是在使用填充/边距时。

两个选项…

1. 设置格式检测元标记。

要删除所有电话号码的自动格式化,请将以下内容添加到html文档的头部:

<meta name="format-detection" content="telephone=no">

查看更多苹果特定的元标签键。

注意:如果你在页面上有电话号码,你应该手动将它们格式化为链接: < a href = "电话:+ 1-555-555-5555 " > 1-555-555-5555 < / >


2. 不能设置元标签?想要使用css?

两个css选项:


选项1(更适合网页)

使用css属性选择器来目标href值以tel开头的链接:

a[href^="tel"] {
  color: inherit; /* Inherit text color of parent element. */
  text-decoration: none; /* Remove underline. */
  /* Additional css `propery: value;` pairs here */
}

选项2(更适合html电子邮件模板)

或者,当你不能设置元标签时,比如在html电子邮件中,在链接/锚标签中包装电话号码(<a href=""></a>),然后使用类似于下面的css来定位它们的样式,并调整你需要重置的特定属性:

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;
}

如果你想要针对特定的链接,在你的链接上使用类,然后更新上面的css选择器为[x-apple-data-detectors].class-name。

我来详细阐述一下David Thomas之前的建议:

a[href^="tel"]{
    color:inherit;
    text-decoration:none;
}

将此添加到css中会保留电话号码的功能,但会去掉下划线并匹配您最初使用的颜色。

a[href^=tel]{
    color:inherit;
    text-decoration: inherit;
    font-size:inherit;
    font-style:inherit;
    font-weight:inherit;

我用了一个简单的技巧,在电话号码中间添加一个隐藏对象。

<span style="color: #fff;">
0800<i style="display:none;">-</i> 9996369</span>

这将帮助你覆盖手机号码颜色的IOS。