方案一:使用 pointer-events:none
img{
pointer-events:none;
}
方案二:全局属性
*{
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
-webkit-touch-callout主要用于禁止长按菜单。当然针对webkit内核的浏览器。
user-select属性是css3新增的属性,用于设置用户是否能够选中文本。
方案三:加一层遮罩层
<div class="imgbox">
<div class="imshar"></div>
<img src=""/>
</div>
<style>
.imgbox{
position: relative;
width: 80%;
margin: 0 auto;
margin-top: 20px;
}
.imgbox .imshar{
position: absolute;
z-index: 100;
left: 0;
right: 0;
top: 0;
bottom: 0;
opacity: 0;
}
.imgbox img{
display: block;
width: 100%;
}
</style>