css禁止选中指定文本代码实例_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:29:21
Original
1220 people have browsed it

css禁止选中指定文本代码实例:
在实际编码中可能有这样的需求,那就禁止指定的元素可以被选中,下面就通过代码实例介绍一下如何实现此效果。代码如下:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">div{  -webkit-user-select:none;   -moz-user-select:none;  -ms-user-select:none;  -o-user-select:none;  user-select:none;  width:150px;  height:100px;  background:#ccc;  margin:0px auto;   font-size:12px;}</style></head><body><div>蚂蚁部落欢迎您,只有努力奋斗才会有美好的未来。</div></body></html>
Copy after login

上面的代码实现了禁止选中div中元素的效果,不过在当前来说此代码还是有缺陷的,因为IE9以下的浏览器并不支持,需要用javascript做一下处理才能够兼容所有的主流浏览器,具体可以参阅兼容所有浏览器的禁止选中文本代码实例一章节。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=14514

更多内容可以参阅:http://www.softwhy.com/divcss/

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template