禁止文字选中兼容IE/Chrome等浏览器 css方法

2024-02-15 18:05:38 举报文章

如果让整个页面都禁止选择,可以使用下面的css

body{
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

如果希望指定元素禁止访问,请看下面的示例代码:

<!doctype html>
<html>
<head>
<style type="text/css">
*.unselectable {
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;

   /*
     Introduced in IE 10.
     See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/
   */
   -ms-user-select: none;
   user-select: none;
}
</style>
</head>

<body>

<div class="unselectable">
<p>这是很长的一段文本。啦啦啦啦啦啦</p>
</div>

</body>
</html>
如果你认为本文可读性较差,内容错误,或者文章排版错乱,请点击举报文章按钮,我们会立即处理!