好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

user-select属性详解

user-select 属性是css3规范中新增的一个功能,用于设置或检索 是否 允许用户选中文本,使用语法是“user -s elect:none |text| all | element”,其默认值是text,并且适用于除替换元素外的所有元素。

本文操作环境:Windows7系统,CSS3版本,Dell G3 电 脑。

user-select ,设置或检索是否允许用户选中文本

user-select语法:

user-select:none |text| all | element

默认值:text

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

继承性:无

动画性:否

计算值:指定值

取值:

none:文本不能被选择

text:可以选择文本

all:当所有内容作为一个整体时可以被选择。如果双击 或者 在上下文上点击子元素,那么被选择的部分将是以该子元素向上回溯的最高祖先元素。

element:可以选择文本,但选择范围受元素边界的约束

说明:

设置或检索是否允许用户选中文本。

IE6-9不支持该属性,但支持使用标签属性 onselectstart="return false;" 来达到 user-select:none 的效果;Safari和Ch rom e也支持该标签属性;

直到 opera 12.5仍然不支持该属性,但和IE6-9一样,也支持使用私有的标签属性 unselectable="on" 来达到 user-select:none 的效果;unselectable 的另一个值是 off;

除C hr ome和Safari外,在其它浏览器中,如果将文本设置为 -ms-user-select:none;,则用户将无法在该文本块中 开始 选择文本。 不过 ,如果用户在页面的其他区域开始选择文本,则用户仍然可以继续选择将文本设置为 -ms-user-select:none; 的区域文本;

对应的脚本特性为userSelect。

【推荐学习:CSS视频教程】

兼容性:

浅绿 = 支持

红色 = 不支持

粉色 = 部分支持

实例

<!DOCTY PE  ht ML >
<html>
<head>
< ;m eta charset="utf-8" />
<t IT le></title>
<meta http-equiv="X-UA-Compatible" content="IE= Edge ,chrome=1" />
<style>
. test {
padding:10px;
- webkit -user-select:none;
-moz-user-select:none;
-o-user-select:none;
user-select:none;
background: # eee;}
</style>
</head>
<body>
<div onselectstart="return false;" unselectable="on">选择我试试,你会发现怎么也选择不到我,哈哈哈哈</div>
</body>
</html>

效果图:

以上就是user-select属性详解的详细内容,更多请关注其它相关 文章 !

总结

以上是 为你收集整理的 user-select属性详解 全部内容,希望文章能够帮你解决 user-select属性详解 所遇到的问题。

如果觉得 网站内容还不错, 推荐好友。

查看更多关于user-select属性详解的详细内容...

  阅读:32次