如何使某些文本不能用CSS选择 [英] How to make certain text not selectable with CSS

查看:95
本文介绍了如何使某些文本不能用CSS选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面的标题有一些居中的文本,但我不想让用户能够选择它。

The header for my page has some centered text, but I do not want the user to be able to select it. Is there a way to do this with CSS?

推荐答案

下面的CSS阻止用户选择文本。

The CSS below stops users from being able to select text.

-webkit-user-select: none; /* Chrome/Safari */        
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */

/* Rules below not implemented in browsers yet */
-o-user-select: none;
user-select: none;

目标IE9向下和Opera的html属性 unselectable 必须改为:

To target IE9 downwards and Opera the html attribute unselectable must be used instead:

<p unselectable="on">Test Text</p>

这篇关于如何使某些文本不能用CSS选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆