css - 用户选择 : all inheritance not working in chrome 62

标签 css google-chrome

我刚刚将我的 PC 和 Mac 上的 Google Chrome 升级到版本 62,CSS 属性 user-select: all 已停止正常工作。

如果您的父项的 user-select 设置为 none,而子项的 user-select 设置为 all,则父项属性不会被正确覆盖。

-webkit-user-select: all;
-moz-user-select: all;
-ms-user-select: all;
user-select: all;

有没有其他人遇到过这种情况,知道这是新版 Google Chrome 中的错误还是有正确的实现方法?

这是演示问题的代码(使用 Chrome 62 查看问题)- JSFiddle :

div {
  margin: 5px;
}
.parent {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.child {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}
<div class="parent">
  <div class="child">
    Parent has user-select set to none, Try to select this text
  </div>
</div>

<div class="child">
  No parent, Try to select this text
</div>

最佳答案

这是 Chrome 浏览器的问题。该错误已被报告。您可以在 this bug report 上通过另一个(无效示例)找到有关该错误的更多详细信息.


在错误修复之前,您可以使用一些 JavaScript 来获得行为。参见 this answer on StackOverflow .


另一种非 JavaScript 解决方案如下:

.parent :not(.selectable-all) {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.selectable-all {
  -webkit-user-select: all;
  -moz-user-select: all;
  -ms-user-select: all;
  user-select: all;
}
<div class="parent">
  <span>user-select set to none and not selectable all.</span>
  <div class="child selectable-all">
    Parent has user-select set to none, Try to select this text
  </div>
</div>

<div class="child selectable-all">
  No parent, Try to select this text
</div>

关于css - 用户选择 : all inheritance not working in chrome 62,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46883622/

相关文章:

javascript - CSS-将页脚粘贴到页面底部(因此仅在滚动后可见)没有 html 选择器?

javascript - jQuery 选项卡和 shift+tab 显示导航

当多次使用 css 类时,Javascript 无法正常工作?

php - 在 Symfony 2.8 中使用 app_dev.php 时无法访问真实文件

javascript - document.querySelectorAll ('a:visited' ) 不起作用

html - Bootstrap 3.0.3 form-group 类它不采用任何边距底部

javascript - 在 Chrome 中强制全屏

javascript - 如果浏览器关闭,Google Chrome 推送通知无法正常工作?

jquery - 使用 jquery 的 Chrome 上的 Flex 无法正确呈现

google-chrome - DOM 异常 : Failed to register a ServiceWorker: The script does not have a MIME type