CSS禁止选中文字

通过CSS属性,禁止选中文字

效果预览

CSS

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

HTML测试

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS禁用选中文字</title>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <style type="text/css">
        .no-select {
            /* iOS Safari */
            -webkit-touch-callout: none;
            /* Chrome/Safari/Opera */
            -webkit-user-select: none;
            /* Konqueror */
            -khtml-user-select: none;
            /* Firefox */
            -moz-user-select: none;
            /* Internet Explorer/Edge */
            -ms-user-select: none;
            /* Non-prefixed version, currently not supported by any browser */
            user-select: none;
        }
    </style>
</head>
<body>
<div style="text-align: center;top: 200px;">
    <h1>可以选择</h1>
    <h1 class="no-select">不可以选择</h1>
</div>
</body>
</html>
posted @ 2020-07-17 16:48  吃猫的鱼℘  阅读(577)  评论(0编辑  收藏  举报
Document