在 web 浏览器中,如果我们在文本上双击,文本会被选取或高亮显示。那么如果我们要禁止这种行为该怎么办呢?其实很简单,使用下面的属性就可以了。
user-select 属性规定是否能选取元素的文本。
在 web 浏览器中,如果您在文本上双击,文本会被选取或高亮显示。此属性用于阻止这种行为。
语法:
user-select: auto|none|text|all;
属性值:
-
auto 默认。如果浏览器允许,则可以选择文本。
-
none 防止文本选取。
-
text 文本可被用户选取。
-
all 单击选取文本,而不是双击。
实现代码如下:
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; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)