css可以使用user-select属性设置文字无法选中。
css设置文字无法选中代码如下:
-webkit-user-select:none; -moz-user-select:none; -ms-user-select:none; user-select:none;
user-select
语法:
user-select:none |text| all | element
默认值:text
适用于:除替换元素外的所有元素
继承性:无
动画性:否
计算值:指定值
取值:
none:文本不能被选择
text:可以选择文本
all:当所有内容作为一个整体时可以被选择。如果双击或者在上下文上点击子元素,那么被选择的部分将是以该子元素向上回溯的最高祖先元素。
element:可以选择文本,但选择范围受元素边界的约束
示例:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></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>
推荐:css文档
以上就是css中文字无法选中怎么设置?的详细内容,更多请关注0133技术站其它相关文章!