您的位置:首页 > Web前端 > CSS

使用CSS里的user-select属性控制用户在页面上选中的内容

2017-11-20 20:46 267 查看
原文地址:https://www.cnblogs.com/137dawn/p/6697894.html

CSS里的user-select属性用来禁止用户用鼠标在页面上选中文字、图片等,也就是,让页面内容不可选。也可以只允许用户选中文字,或者全部都放开,用户可以同时选中文字、还包括文本里的图片、视频等其它东西。user-select属性的作用是元素级别的,它不仅可以作用整个页面,也可以只在指定的元素和其子元素上生效。
  “user-select”属性在各大浏览器里都还是实验性的属性,以后有可能废弃,也有可能转正,目前使用各种浏览器引擎前缀,它的作用还是能发挥的不错的。
 

user-select: none;
user-select: auto;
user-select: text;
user-select: contain;
user-select: all;
//火狐浏览器
-moz-user-select: none;
-moz-user-select: text;
-moz-user-select: all;
//谷歌浏览器
-webkit-user-select: none;
-webkit-user-select: text;
-webkit-user-select: all;
//IE
-ms-user-select: none;
-ms-user-select: text;
-ms-user-select: all;
-ms-user-select: element;


none:禁止用户选中
text:对用户的选择没有限制
all:目标元素将整体被选中,也就是说不能只选中一部分,在你用鼠标选中部分文字时,浏览器会自动选中整个元素里的内容。(谷歌浏览器里好像不太灵?)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: