【问题标题】:Phonegap styles -webkit-user-select: none; disabling text fieldPhonegap 样式 -webkit-user-select: none;禁用文本字段
【发布时间】:2012-10-10 05:36:25
【问题描述】:

我对 Phonegap 还是很陌生。我有一个问题,在干净的 Phonegap 项目中使用的默认 css 不允许输入到文本字段中。我把它缩小到一行 CSS:

* {
            -webkit-touch-callout: none;                /* prevent callout to copy image, etc when tap to hold */
            -webkit-text-size-adjust: none;             /* prevent webkit from resizing text to fit */
            -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
            -webkit-user-select: none;                 /* prevent copy paste, to allow, change 'none' to 'text' */

    }

问题线是:

-webkit-user-select: none; 

这可以在 www/index.css 中找到。

似乎完全禁用输入字段并不是想要的效果。

我之前也发布过 2 次此问题,但已关闭,不知道为什么...由于不是常见问题,我的问题已关闭。好吧,我只能说,我猜 stackoverflow 的一些用户不认为 CSS 3、Phonegap、HTML 5 和 -webkit-user-select: 是常见的情况。我不同意。

但是我可以看到这个问题也在这里发布,也导致 Safari 出现问题:User select:none causes input field to be inaccessible on Safari 虽然略有不同。

我目前的解决方案是这样的:

-webkit-user-select: text; /* change 'none' to 'text' */

只是仍然好奇启用文本输入的最优雅的解决方案是什么,但仍然保留了 Phonegap 试图实现的一些副本和过去的功能。谢谢!

【问题讨论】:

  • 请记住,有些设备使用非 Webkit 浏览器。

标签: html css cordova


【解决方案1】:

尝试将其添加到您的 css 中:

input {
    -webkit-user-select: auto !important;
}

这将覆盖您在输入字段的每个元素(通过 * 选择器)上设置的禁用文本选择。

【讨论】:

【解决方案2】:

这样给css添加规则就行了:

*:not(input,textarea) {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}

【讨论】:

【解决方案3】:

user-select 可能会导致 contenteditable="true" 的元素出现问题,所以最好也添加它

  [contenteditable="true"] , input, textarea {
        -webkit-user-select: auto !important;
        -khtml-user-select: auto !important;
        -moz-user-select: auto !important;
        -ms-user-select: auto !important;
        -o-user-select: auto !important;
        user-select: auto !important;  
  }

【讨论】:

  • 我在 iPAD 的 safari 和 chrome 中遇到了同样的问题。我能够修复这个 CSS 非常有用。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2019-07-17
  • 2018-05-30
  • 1970-01-01
  • 1970-01-01
  • 2021-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多