简体   繁体   English

如何无条件地将 webkit-tap-highlight-color 应用于 div 元素?

[英]How to apply webkit-tap-highlight-color to a div element unconditionally?

The application result changes depending on the conditions as follows.申请结果根据以下条件而变化。

// I checked these with Safari on iOS.
<span>onclick + inline-block + short text: OK</span><br>
<div onclick="" class="d-inline-block">AAAAAA</div><br>

<span>onclick + block + short text: Not Working</span><br>
<div onclick="" class="d-block">AAAAAA</div><br>

<span>block + short text: Not Working</span><br>
<div class="d-inline-block">AAAAAA</div><br>

<span>onclick + inline-block + long text: Not Working</span><br>

<div onclick="" class="d-inline-block">AAAAAAAAAA</div><be>

Codepen密码笔

I don't know if changing the display or the number of characters will change the result, although I checked the specifications.虽然我检查了规格,但我不知道更改显示或字符数是否会改变结果。

Here is a quote from the specifications :这是规范中的引述:

By default, when the user taps a link or a JavaScript clickable element, Safari on iOS highlights the area in a transparent gray color默认情况下,当用户点击链接或 JavaScript 可点击元素时,iOS 上的 Safari 会以透明灰色突出显示该区域

So, I have two questions:所以,我有两个问题:

  1. How to apply webkit-tap-highlight-color to a div element unconditionally?如何无条件地将 webkit-tap-highlight-color 应用于 div 元素?
  2. What are the specific conditions to which "webkit-tap-highlight-color" applies? “webkit-tap-highlight-color”适用的具体条件是什么?
  3. Why is the result changed with the String length?为什么结果会随着字符串长度而改变?
  4. Why is the result changed with the display property?为什么显示属性会改变结果?

3, 4 is not required, but I'm glad if you take these questions. 3、4 不是必需的,但如果您回答这些问题,我很高兴。

-webkit-tap-highlight-color is not supported with safari. safari 不支持-webkit-tap-highlight-color Please visit this for more information about compatibility.请访问此处以获取有关兼容性的更多信息。

 document.querySelector("#div").addEventListener("click", () => { console.log("div clicked"); });
 * { -webkit-tap-highlight-color: red; }
 <a href="javascript:void(0);">this is link</a> <button>this is button</button> <div id="div">this is div</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM