使用CSS里的user-select属性控制用户在页面上选中的内容
2018-07-08 10:01
621 查看
CSS里的user-select属性用来禁止用户用鼠标在页面上选中文字、图片等,也就是,让页面内容不可选。也可以只允许用户选中文字,或者全部都放开,用户可以同时选中文字、还包括文本里的图片、视频等其它东西。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;
下面是“user-select”属性的属性值介绍:
none
- 禁止用户选中
text
- 对用户的选择没有限制
all
- 目标元素将整体被选中,也就是说不能只选中一部分,在你用鼠标选中部分文字时,浏览器会自动选中整个元素里的内容。(谷歌浏览器里好像不太灵?)
相关文章推荐
- 使用CSS里的user-select属性控制用户在页面上选中的内容
- 使用CSS里的user-select属性控制用户在页面上选中的内容
- 使用CSS里的user-select属性控制用户在页面上选中的内容
- 使用 CSS3 新属性 user-select 控制网页内容的选择范围
- 使用 CSS3 新属性 user-select 控制网页内容的选择范围
- css 让文字不被选中之-moz-user-select 属性介绍
- css控制页面文字不能被选中user-select:none;
- css 让文字不被选中 之 -moz-user-select 属性
- css控制页面文字不能被选中user-select:none;
- CSS3新属性之user-select控制文本是否选中
- css控制页面文字不能被选中user-select:none;
- 使用CSS的position属性控制页面布局的入门教程
- 使用jQuery和CSS控制页面打印区域
- 使用jQuery和CSS控制页面打印区域
- css控制文章内容页面中图片大小
- 使用HttpContext的User属性来实现用户验证
- 简单标签的使用自定义标签控制页面内容(标签体)是否输出、
- 使用jQuery和CSS控制页面打印区域
- 使用HttpContext的User属性来实现用户验证
- 使用HttpContext中的User属性来实现用户身份验证之用户验证票篇