在css中,可以使用user-select属性来禁止选中文字,只需要给文本文字元素添加“user-select:none;”样式即可。user-select属性可以设置或检索是否允许用户选中文本,当值为“none”时表示文本不能被选择。
本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。
在css中,可以使用user-select属性来禁止选中文字。
user-select属性设置或检索是否允许用户选中文本
语法:
立即学习“前端免费学习笔记(深入)”;
user-select:none |text| all | element
属性值:
none:文本不能被选择
text:可以选择文本
all:当所有内容作为一个整体时可以被选择。如果双击或者在上下文上点击子元素,那么被选择的部分将是以该子元素向上回溯的最高祖先元素。
lement:可以选择文本,但选择范围受元素边界的约束
禁止选中文字的代码
pc端:
.not-select{ -moz-user-select:none; /*火狐*/ -webkit-user-select:none; /*webkit浏览器*/ -ms-user-select:none; /*IE10*/ -khtml-user-select:none; /*早期浏览器*/ user-select:none; }
移动:
.no-touch { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
补充:js方法:
ontouchstart="return false;"
在需要禁止的dom上添加这段代码,两种方法对于安卓和IOS的支持没有单独测试过。两个同时使用,对于安卓和IOS可以起到禁止作用。
(学习视频分享:css视频教程)
以上就是css怎么禁止选中文字的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号