HTML + CSS z-index 不工作

标签 html css z-index

我有一个非常恼人的问题,即我的 z-index 不工作并且 div 位于另一个 div 的上方(在 y 轴上)而不是在(在 z 轴上)上方。

这可能是完全显而易见的,但我看不出我的代码有问题。谁能发现我哪里出错了?它应该很容易,但我很沮丧,因为我找不到解决方案。

<style>
.greenleftarrow{
position: relative;
z-index:10;
display:block;
background:#fff url(./images/greenleftarrow.jpg) no-repeat;
left:10px;
top: 0px;
height:140px;
opacity:0.5;
filter:alpha(opacity=50);
}

</style>


<body id="body1" style="position: relative; z-index:-1; height: 510px;" onload="javascript:showAndroidToast('1'); inspectLang(); getDocHeight()">
<div class="greenleftarrow"  id="greenleftarrow" ></div>
<div  style="position: relative; z-index:-1;">body body body body</div>
</body>

最佳答案

尝试将箭头的位置改为绝对位置。

  .greenleftarrow{
  position: absolute;
  z-index:10;
  display:block;
  background:#fff url(./images/greenleftarrow.jpg) no-repeat;
  left:10px;
  top: 0px;
  height:140px;
  opacity:0.5;
  filter:alpha(opacity=50);
  }

关于HTML + CSS z-index 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8415092/

相关文章:

html - 背景图像上的径向渐变圆叠加

jquery - 简单的 Jquery 事件不起作用

css - Bootstrap 3 : how to set 2 html div side by side in the header?

html - 文本越过导航栏

javascript - 如何将 jquery slider 设置为自动而不是单击或悬停在拇指上

html - CSS div 在另一个 div 中的位置

html - 为什么我的子菜单没有显示?

html - 如何为一个父元素的子元素提供比另一个父元素更高的 z-index?

Javascript:在多个元素(ID 和类)上设置 Z-Index

Firefox 全屏视频追加 DOM 元素