首页 > 解决方案 > 当我单击 iPhone 上的输入时,是什么导致灰色闪烁?

问题描述

使用我的 iPhone 预览我正在处理的网页时,我注意到每当我点击一个输入时,我都会看到它后面出现短暂的灰色闪光。

我已经去掉了所有的 CSS,但仍然存在灰色闪烁。它在桌面 Safari 上不可见,仅在移动 Safari 上可见。

是什么原因造成的?我该如何阻止它发生?

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Why do the inputs flash?</title>

  <style type="text/css">
    input {
      display: block;
      width: 100%;
      border-width: 0 0 1px 0;
      border-radius: 0px;
    }
  </style>
</head>
<body>
  <input type="radio" name="mode" id="mode1" value="mode1">
  <label for="mode1">Mode 1</label>

  <input type="radio" name="mode" id="mode2" value="mode2">
  <label for="mode2">Mode 2</label>

  <input type="radio" name="mode" id="mode3" value="mode3">
  <label for="mode3">Mode 3</label>

  <label for="hello">
    <input checked type="checkbox" id="hello">
    <span class="toggle">
      <span class="switch"></span>
    </span>
    <span class="label">Check me</span>
  </label>
  
  <form action="">
    <label for="text-input">
      Enter text
      <input type="text">
    </label>

    <label for="email-iput">
      Enter email here
      <input type="email">
    </label>
  </form>
</body>
</html>

灰色闪烁输入

标签: htmlcss

解决方案


我用谷歌搜索了美国拼写gray并找到了关于 CSS-tricks的答案。

-webkit-tap-highlight-color: rgba(0,0,0,0); 然后允许:active styles在 Mobile Safari 的页面上使用 CSS: document.addEventListener("touchstart", function(){}, true);

编辑

实际上,我只需要-webkit-tap-highlight-color: rgba(0,0,0,0);覆盖灰色闪光。


推荐阅读