【问题标题】:How can I remove the blue styling on phone?如何去除手机上的蓝色样式?
【发布时间】:2022-01-14 07:42:51
【问题描述】:

我正在建立一个网站,除了 iPhone 上的链接外,移动设备中的所有样式都可以正常工作。我已经尝试了这个线程中的解决方案:How do I remove the blue styling of telephone numbers on iPhone/iOS?

我试过这个CSS:

a[href^="tel"],
span[href^="tel"] {
  color: inherit !important;
  text-decoration: none !important;
  font-size: inherit !important;
  font-family: inherit !important;
  font-weight: inherit !important;
  line-height: inherit !important;
}

还有这个CSS:

a[x-apple-data-detectors],
span[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 解决此问题以便我的所有网页都继承样式的任何建议?

更新解决方案

接受的答案将改变所有<span> / <a> 元素的默认行为。相反,您应该在元素上使用 id 或 class 设置样式。示例可能如下所示:

.lnd-header-button__text{  
    all: initial;
  }

  .lnd-header-button__text * {
   all: unset;
  }

【问题讨论】:

  • 不包括当前标记 (HTML) 和 CSS 赋予链接颜色的内容(您可以通过检查元素找到此内容),邀请解决方案/答案可能会影响比您更多的元素想要样式和解决方案对 CSS 应用比必要的更高的特异性。这使您更难以将后续的 CSS 声明应用于您的元素。
  • 我更新了帖子,希望这是您正在寻找的内容,感谢您的解释,我明白您的意思。 @tao

标签: html css


【解决方案1】:

你可以通过媒体查询来做到这一点

小心使用精确选择器,因为使用 css all 会影响匹配选择器的所有 css 属性

@media only screen and (max-width: 600px) {
  my-selector {  
    all: initial;
  }

  my-selector * {
   all: unset
  }
}

【讨论】:

  • 对使用的选择器很可能过于通用的事实发出警告就足够了。感谢您提高答案的质量。
猜你喜欢
  • 2017-12-16
  • 1970-01-01
  • 2012-02-01
  • 2011-04-13
  • 1970-01-01
  • 2022-12-13
  • 1970-01-01
  • 1970-01-01
  • 2017-03-16
相关资源
最近更新 更多