0

您好,所以我试图在切换元素时显示一个 div。函数和事件肯定有效,因为如果我删除样式,那么元素就会出现,但是当我添加它时,它就消失了,我实际上不知道为什么。当我添加时它消失了,position:absolute但即使我将高度和宽度设置为 100% 并且它没有跟随。这是我的沙盒。

这是我的CSS:

* {
  box-sizing: border-box;
}

html,
body,
#root {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  user-select: none;
  background: lightblue;
}
.Main {
  height: 100%;
  width: 100%;
  position: abosolute;
}

.Contain {
  border-radius: 50%;
  box-shadow: 50px rgba(0, 0, 0, 0.05);
  position: absolute;
  height: 50px;
  width: 50px;
  padding-left: 20px;
  margin-bottom: 20px;
  z-index: 998;
  cursor: pointer;
}
.Contain p {
  color: white;
}

.Item {
  width: 100%;
  height: 100%;
  background: white;
  border-radius: 5px 30px 30px 5px;
  will-change: transform, opacity;
  position: absolute;
  display: inline-block;
  bottom: 0.1%;
  box-shadow: 50px rgba(0, 0, 0, 0.05);
}
.Item p {
  color: black;
}

.Buttons {
  top: 20%;
  left: 25%;
  z-index: 998;
  position: absolute;
}



.Overlay {
  background-color: #282c34;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: white;
  box-shadow: 0px 10px 10px -5px rgba(0, 0, 0, 0.05);
  z-index: 999;
  position: absolute;
}

我会发布 JSX,但它们位于不同的页面中,可能更容易看到沙箱

谢谢!

4

1 回答 1

0

所以我发现导致我的样式出现问题的原因是我<a.div>的覆盖组件周围减少了样式。所以我将 div 的样式设置为position: 'sticky'andtop:0和 width 和 height 为 100%。

另一个 div 的任何子元素都将被设置为相对于父 div 的样式,因此父 div 必须相应地设置样式

于 2020-05-07T09:42:44.150 回答