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:目標元素將整體被選中,也就是說不能只選中一部分,在你用鼠標選中部分文字時,瀏覽器會自動選中整個元素里的內容。(谷歌瀏覽器里好像不太靈?)