• 技术文章 >web前端 >html教程

    html怎么禁止文字选择

    青灯夜游青灯夜游2021-12-13 13:48:46原创273

    在html中,可以利用user-select属性来禁止文字选择,只需要给文本元素添加“user-select:none;”样式即可;user-select属性用于设置用户是否能够选中文本,当值为“none”可让文本不能被选择。

    本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

    html中禁止文字被选中

    user-select: none |text| all | element;

    取值:

    说明:

    1、IE6-9不支持该属性,但支持使用标签属性 onselectstart="return false;" 来达到 user-select:none 的效果;Safari和Chrome也支持该标签属性;

    2、直到Opera12.5仍然不支持该属性,但和IE6-9一样,也支持使用私有的标签属性 unselectable="on" 来达到 user-select:none 的效果;unselectable 的另一个值是 off;

    3、除Chrome和Safari外,在其它浏览器中,如果将文本设置为 -ms-user-select:none;,则用户将无法在该文本块中开始选择文本。不过,如果用户在页面的其他区域开始选择文本,则用户仍然可以继续选择将文本设置为 -ms-user-select:none; 的区域文本;

    4、对应的脚本特性为userSelect

    html

    <!DOCTYPE html>
    <html>
     
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>user-select</title>
    </head>
    <style>
        .test {
            padding: 10px;
            -webkit-user-select: none;
            -moz-user-select: none;
            -o-user-select: none;
            user-select: none;
            background: #eee;
        }
    </style>
     
    <body>
        <div onselectstart="return false;" unselectable="on">禁止选中文本内容</div>
    </body>
     
    </html>

    推荐教程:《html视频教程

    以上就是html怎么禁止文字选择的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:html 禁止选中文字
    上一篇:怎么进行文件上传?分享HTML文件上传的10个小技巧 下一篇:html div怎么设置宽度
    PHP编程就业班

    相关文章推荐

    • html怎么设置边框颜色• html怎么将表格边框隐藏• html怎么设置粗体• html怎么设置网页颜色• html怎么设置input的宽度自适应• html下拉列表怎么做的

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网