html - user-select:none 仍然是 Chrome 中复制的富文本的一部分
问题描述
我正在尝试使用此答案将超链接从 Chrome 复制并粘贴为纯文本,当我粘贴到记事本时它似乎可以工作。但是,无论如何user-select: none;
,当我将相同的剪贴板内容粘贴到 Libreoffice Writer 时,所有文本都会被粘贴。当样式块被可选块包围时会发生这种情况。
.unselectable {
position: absolute;
z-index: 1;
color: green;
user-select: none;
-webkit-user-select: none;
}
.selectable {
position: absolute;
z-index: 2;
color: rgba(0, 0, 0, 0);
user-select: text;
-webkit-user-select: text;
}
xxx
<p style="user-select: none;">
<a href="mailto:unselectable@b.org">unselectable</a>
</p>
<p>
<a href="mailto:default@b.org">default</a>
</p>
<div>
<p unselectable="on" class="unselectable">unselectable2</p>
<p>zzz</p>
</div>
解决方案
原来这是Chrome中的一个错误。
一种解决方法是使用-web-kit
.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>un-selectable</span>
<div class="child selectable-all">
Selectable
</div>
</div>
<div class="child selectable-all">
Selectable
</div>
我试过了,效果很好。试着让我知道它是否也对你有用。
这是一个供参考的链接;用户选择:所有继承在 chrome 62 中都不起作用
推荐阅读
- c# - 交叉绑定复选框 - isChecked #1 -> isEnabled #2
- c - 我的终端只打印 main 的第一个输出
- r - rmarkdown data.table 编译后绘图不匹配
- string - 在 IDL 中连接字符串和整数时出现错误的空格
- c# - 异步方法在android后台服务xamarin中不起作用
- javascript - 更改重点元素的 ng-model
- python - 如何在子进程中使用 sshkey
- node.js - 使用 Bluebird 在 typescript 中引发编译错误
- c# - Xamarin C# 无法将 c# 类转换为 Android.content.context
- asp.net - 如何在 Web API 中执行 Action Method 之前调用特定函数?