2

使用我的 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>

灰色闪烁输入

4

3 回答 3

2

我用谷歌搜索了美国拼写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);覆盖灰色闪光。

于 2021-09-28T14:49:02.527 回答
0

使用display: inline-block;代替display: block;

在 IOS 15 的最新 Safari 版本中测试

这是一个例子:

/* Ignore this */

* {
  margin: 0;
  padding: 0;
}

/* Width part */

#first {
  display: block;
  background: red;
}

#second {
  display: inline-block;
  background: red;
}
<p id="first">This has a 100% width</p>

<br>

<p id="second">This text has a background color based on the texts lenght</p>

所以改变这个:

input {
  display: block;
  width: 100%;
  border-width: 0 0 1px 0;
  border-radius: 0px;
}

对此:

input {
   display: inline-block;
   width: 100%;
   border-width: 0 0 1px 0;
   border-radius: 0px;
}

或者只是这个:

input {
  display: inline-block;
}
<input type="checkbox">

于 2021-09-28T14:18:05.883 回答
0

单选和复选框元素不应使用您正在使用的宽度属性。无论它是什么,它都应该是固定的元素大小。如果你想让它占据一整行,你应该把它包装在一个 div 中。如下。

但是,可能有一种 CSS 方法可以通过使用 :focus 选择器来管理颜色。但我无法测试它,因为我无法访问 iPhone。

input:focus {
    background-color:yellow;
}

<!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;
      border-width: 0 0 1px 0;
      border-radius: 0px;
    }

  </style>
</head>
<body>
  <div class="i-should-be-full-width">
    <input type="radio" name="mode" id="mode1" value="mode1">
  </div>
  <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>

于 2021-09-28T14:25:23.163 回答