CSS中禁止用户选中文字

 

在生产过程中有时我们不希望用户双击选中文字,可以通过下面的CSS代码来实现,可兼容除IE 9和更早IE版本之外的所有浏览器。

css样式

.noselect {
  -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
     -khtml-user-select: none; /* Konqueror HTML */
       -moz-user-select: none; /* Firefox */
        -ms-user-select: none; /* Internet Explorer/Edge */
            user-select: none; /* Non-prefixed version, currently
                                  supported by Chrome and Opera */
}

html代码

<p>
  可选中文本.
</p>
<p class="noselect">
  禁止选中文本.
</p>

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据