HTML + CSS z 索引不起作用

发布于 2024-12-20 00:17:55 字数 721 浏览 0 评论 0原文

我有一个非常烦人的问题,即我的 z 索引不起作用,并且 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>

I have a very annoying problem which is my z-index is not working and the div is sitting above (on the y-axis) and not on top of (on the z-axis) the other div.

This will probably be completely obvious but I cannot see a problem with my code. Can anyone spot where I am going wrong? It should be so easy but I am getting so frustrated because I cannot find a solution.

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤蝉 2024-12-27 00:17:55

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

  .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);
  }

Try to change the position of the arrow to absolute.

  .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);
  }
倚栏听风 2024-12-27 00:17:55

如果我理解正确,您可以使用负上边距将第二个 div 向上移动到 greenleftarrow:

http://jsfiddle.net /XSH2Y/

If I understand correctly, you can use a negative top margin to move the second div upwards onto greenleftarrow:

http://jsfiddle.net/XSH2Y/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文