css禁止选中文本

来源:互联网 发布:手机编写c语言的软件 编辑:程序博客网 时间:2024/05/01 00:39

HTML代码

 

//html 代码

<p>

Selectable text.

</p>

<p class="noselect">

Unselectable text.

</p>

css 代码

 

.noselect {

-webkit-touch-callout: none; /* iOS Safari */

-webkit-user-select: none; /* Chrome/Safari/Opera */

-khtml-user-select: none; /* Konqueror */

-moz-user-select: none; /* Firefox */

-ms-user-select: none; /* Internet Explorer/Edge */

user-select: none; /* Non-prefixed version, currently

not supported by any browser */

}

在 IE < 10 和Opera < 15中我们需要在需要禁止选中的元素上面添加一个属性

unselectable="on",否则可能不会生效哦~不过现代浏览器如果不是非得兼容一些老的浏览器也可以不加。

0 0
原创粉丝点击