如何使某些文本无法使用 CSS 选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6900124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make certain text not selectable with CSS
提问by jmasterx
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 做到这一点?
回答by tw16
The CSS below stops users from being able to select text.
下面的 CSS 阻止用户选择文本。
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+/Edge */
user-select: none; /* Standard */
To target IE9 downwards the html attribute unselectable
must be used instead:
要向下定位 IE9,unselectable
必须改用html 属性:
<p unselectable="on">Test Text</p>
回答by Erre Efe
Use a simple background image for the textarea suffice.
对 textarea 使用简单的背景图像就足够了。
Or
或者
<div onselectstart="return false">your text</div>