【发布时间】:2016-02-23 09:08:59
【问题描述】:
【问题讨论】:
-
你应该为图片设置
pointer-events: none;。请注意support -
当您使用 png 图像时,您可以将其用作背景,并且您可以轻松地根据屏幕截图中显示的要求定位按钮,或者您也可以使用按钮的绝对位置.. 像这样jsfiddle.net/3qxjbrL9/3
【问题讨论】:
pointer-events: none;。请注意support
使用z-index,确实可以:
button.btn-class {
z-index: 999;
}
编辑 - 您显然需要确保图像 z-index 低于上面的 999!
【讨论】:
如 cmets 中所述...不调整图像的 z-index(这显然不是一个选项),您只能禁用图像上的指针事件。
img {
pointer-events:none;
}
Support 是所有现代浏览器,但只有 IE11
糟糕的演示:
body {
margin: 0;
padding: 0;
}
div {
height: 400px;
display: flex;
flex-direction: column;
}
button {
align-self: flex-start;
}
img {
opacity: 0.5;
position: relative;
top: -1em;
margin-left: 2em;
border: 1px solid red;
pointer-events: none;
}
<div>
<button>Click Me</button>
<img src="http://lorempixel.com/g/400/200/" alt="" />
</div>
【讨论】:
是的,按钮使用比图像更高的 z-index 值。有关更多信息,请参阅此 link
img{z-index:9;}
button{z-index:99;}
【讨论】:
css 的 z-index 属性仅适用于定位元素(位置:绝对、位置:相对或位置:固定)
使用这个:
.imgclass {
position: relative; //or whatever you want i.e fixed
z-index: -1;
}
.buttonclass {
position: relative;
z-index: 999;
}
【讨论】: