html - 带有用户选择的Div:嵌套在用户选择中时自动不起作用:无
问题描述
我正在使一个 div 不可选择,并且我想在一些嵌套的 div 中重新启用选择。
<div style="user-select: none; -ms-user-select: none; color: red;">
<div id="noSelection">
Should not be able to select this text
</div>
<div id="selectIt" style="user-select: auto; -ms-user-select:auto; color: green;">
Wanna select this text as normal with correct mouse cursor
</div>
</div>
我希望在设置了“自动”的最后一个 div 中正常选择文本,但它在我尝试的任何浏览器中都不起作用。
解决方案
而不是user-select: auto;
用于user-select: text;
使文本可选。正如使用时的规范所述auto
:
如果
user-select
此元素的父元素上none
的计算值为 ,则计算值为none
<div style="user-select: none; -ms-user-select: none; color: red;">
<div id="noSelection">
Should not be able to select this text
</div>
<div id="selectIt" style="user-select: text; -ms-user-select:auto; color: green;">
Wanna select this text as normal with correct mouse cursor
</div>
</div>
推荐阅读
- unity3d - [已解决 - 使用网格碰撞器在 X 和 Y 上进行 3D 运动
- html - Rmarkdown 目录在 HTML knit 文档中 1 秒后消失
- java - 如何使用 Spring AOP 和 SPring boot 进行日志记录
- python - 只为一个用户安装 Python 后,让所有用户都可以使用
- php - 两个表的连接问题
- mysql - golang mysql连接不好
- python - 有没有更快的方法使用 pyglet 和线程在屏幕上绘图?
- ios - 如何在“路径”数组中的通用链接“苹果应用网站关联”文件中识别“www.domainname.com/?v=”
- embedded - 如何在 STM32 Discovery Board 上安装 ST-Link 驱动程序以进行 Visual GDB 调试
- python - 如何在 pandas 中的列之间建立关系?