简体   繁体   English

Chrome不透明过渡z-index问题

[英]Chrome opacity transition z-index issue

I'm working on an angular app and I'm having an issue when adding a '.active' class to a nav item. 我正在开发一个有角度的应用程序,但在向导航项目添加“ .active”类时遇到了问题。

Here is a stackblitz link that demonstrates the issue: 这是一个演示问题的stackblitz链接:

https://stackblitz.com/edit/angular-jjqyft?file=app%2Fapp.component.css https://stackblitz.com/edit/angular-jjqyft?file=app%2Fapp.component.css

Basically, when I click a box, it scales but part of the next box is showing, almost like the active box is transparent. 基本上,当我单击一个框时,它会缩放,但下一个框的一部分会显示出来,就像活动框是透明的一样。 My active class has a z-index of 1 and an opacity of 1. 我的活动班级的z-index为1,不透明度为1。

On Firefox, this doesn't seem to be an issue. 在Firefox上,这似乎不是问题。 Also, I've done something similar using the same technique before (but without any frameworks). 另外,我之前使用相同的技术(但没有任何框架)做过类似的事情。 This link will show you an example from that project. 链接将为您显示该项目的示例。

I'm not sure if I'm doing something wrong or if it's a Chrome issue. 我不确定自己是在做错什么还是Chrome问题。 I appreciate any feedback. 我感谢任何反馈。

EDIT: Just checked on Edge and the same issue is there. 编辑:只是在边缘上检查并且存在相同的问题。 So far it seems like Firefox is the only browser where this issue doesn't exist. 到目前为止,似乎Firefox是唯一不存在此问题的浏览器。

Just add position:relative to either the .section a or .active 只需添加position:relative对于.section a.active

Such as: 如:

.section a {
  display: block;
  width: 120px;
  height: 80px;
  opacity: .5;
  transition: all .5s;
  position:relative;
}

The reason the clicked element seems as if it has opacity <1 is that the next element is actually "above" it, while having opacity: 0.5; 被单击元素看起来好像不透明度<1的原因是,下一个元素实际上是在其“上方”,而具有opacity: 0.5; . By "above it" I mean that the next element is further down the DOM tree, hence having a higher stacking order than the previous (currently the clicked one). “在其上方”是指下一个元素在DOM树的下方,因此具有比前一个(当前被单击的元素)更高的堆叠顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM