【问题标题】:How to make div and img unselectable [duplicate]如何使 div 和 img 不可选择[重复]
【发布时间】:2021-11-17 23:08:47
【问题描述】:

我无法使该代码无法选择。怎么改?

我尝试在所有 css 类中放置 user-select: none,但它仍然是可选的。

<div class="outer">
    <a href="/">
        <img src="/wp-content/themes/theme/assets/img/logo.png">  
    </a>
</div>

【问题讨论】:

    标签: html css


    【解决方案1】:

    没有前缀的所有浏览器都不支持用户选择。试试这个:

    .outer {
      user-select: none;
      -webkit-user-select: none; /* Safari 3.1+ */
      -moz-user-select: none; /* Firefox 2+ */
      -ms-user-select: none; /* IE 10+ */
    }
    

    【讨论】:

    • 奇怪。这个对我有用。在什么浏览器中?你能发布你的完整代码,包括 css 和 html 吗?
    • 我做了一个codepen。可以选择图片吗? codepen.io/bopeterson/pen/oNvbOwa
    【解决方案2】:

    这里已经回答了,我还不能在聊天中发布,抱歉:How to make HTML Text unselectable

    长话短说:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      • 2023-03-09
      • 1970-01-01
      • 2017-12-23
      • 2021-05-29
      相关资源
      最近更新 更多