css怎么禁止选中文字

css怎么禁止选中文字,第1张

css怎么禁止选中文字

在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怎么禁止选中文字的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/693507.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-22
下一篇 2022-04-22

发表评论

登录后才能评论

评论列表(0条)

保存