在css中,可以使用user-select属性来禁止选中文字,只需要给文本文字元素添加“user-select:none;”样式即可。user-select属性可以设置或检索是否允许用户选中文本,当值为“none”时表示文本
          在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怎么禁止选中文字的详细内容,更多请关注自由互联其它相关文章!
