css禁用选中文本_如何使用CSS禁用文本选择

css禁用选中文本

By default browsers let us select the text in the browser using the keyboard, pressing the cmd-A combination on a Mac for example, or using the mouse.

默认情况下,浏览器允许我们使用键盘,例如在Mac上按cmd-A组合或使用鼠标在浏览器中选择文本。

How can you disable that, to make your web page behave more like an app and less like a document?

如何禁用它,以使网页的行为更像是应用程序,而不像文档一样?

Use the user-select: none; CSS rule.

使用user-select: none; CSS规则。

You need to use browser prefixes, as https://caniuse.com/#feat=user-select-none tells us:

您需要使用浏览器前缀,如https://caniuse.com/#feat=user-select-none告诉我们:

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

One thing I use sometimes is to make all the app interface unselectable applying user-select: none; on the body element, then I can re-enable it on specific elements, using:

有时,我使用的一件事是通过user-select: none;使所有应用程序界面变为不可user-select: none; 在body元素上,然后可以使用以下命令在特定元素上重新启用它:

user-select: text;

翻译自: https://flaviocopes.com/css-disable-text-selection/

css禁用选中文本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值