• 纯CSS实现禁止网页文本被选中


    CSS 属性 user-select 控制用户能否选中文本。利用这个css属性的特点,我们可以实现纯css禁止网页文本被选中. 首先我们来看一下css user-select属性语法及取值。

    css user-select语法:

    user-select:none |text| all | element

    默认值:text

    适用于:除替换元素外的所有元素

    继承性:无

    动画性:否

    计算值:指定值

    css user-select取值:

    css user-select取值如下:

    • none:
    • 文本不能被选择
    • text:
    • 可以选择文本
    • all:
    • 当所有内容作为一个整体时可以被选择。如果双击或者在上下文上点击子元素,那么被选择的部分将是以该子元素向上回溯的最高祖先元素。
    • element:
    • 可以选择文本,但选择范围受元素边界的约束

    user-select除Internet Explorer 9及其更早版本外,所有浏览器当前都支持。

    1. .noselect {
    2. -webkit-touch-callout: none; /* iOS Safari */
    3. -webkit-user-select: none; /* Safari */
    4. -khtml-user-select: none; /* Konqueror HTML */
    5. -moz-user-select: none; /* Old versions of Firefox */
    6. -ms-user-select: none; /* Internet Explorer/Edge */
    7. user-select: none; /* Non-prefixed version, currently
    8. supported by Chrome, Edge, Opera and Firefox */
    9. }

    关于这些样式的一些细节的解释:

    • -webkit-user-select是给Chrome,Safari和Opera用的(并不需要使用-o-user-select)。

    • 没有前缀的user-select是被故意略去的。

    • -webkit-touch-callout属性可以让在移动设备上的触摸后弹出失效。就像下面的这些,我们可以让它们不能出现。

    CSS user-select实现禁止文本被选中

    1. <style type="text/css">
    2. .noselect {
    3. -webkit-touch-callout: none; /* iOS Safari */
    4. -webkit-user-select: none; /* Safari */
    5. -khtml-user-select: none; /* Konqueror HTML */
    6. -moz-user-select: none; /* Old versions of Firefox */
    7. -ms-user-select: none; /* Internet Explorer/Edge */
    8. user-select: none; /* Non-prefixed version, currently
    9. supported by Chrome, Edge, Opera and Firefox */
    10. }
    11. </style>
    12. <p>
    13. 这段文本内容可以先被选中。
    14. </p>
    15. <p class="noselect">
    16. 这段文本内容不能被选中。
    17. </p>

    以上是本文的全部类容,感谢阅读,希望能帮到大家。更多教程请访问码农之家    

  • 相关阅读:
    Learn Prompt- Midjourney案例:网页设计
    将“万词王”离线转化为“文络之心“插件之一:复现 wantwords Python/Pytorch 开源项目
    【LeetCode】矩阵模拟相关题目汇总
    【C#异步】异步多线程的本质,上下文流转和同步
    旋转之后截取图像
    BGP社团属性实验
    Qt使用FFmpeg的静态库
    Hbase学习笔记
    OpenCV基本操(IO操作,读取、显示、保存)
    EaselJS 源码分析系列--第一篇
  • 原文地址:https://blog.csdn.net/wuxiaopengnihao1/article/details/126502190