【问题标题】:Div does not display when toggled when styled设置样式时切换时不显示 Div
【发布时间】:2020-08-22 03:09:41
【问题描述】:

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

这是我的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,但它们位于不同的页面中,可能更容易看到沙盒

谢谢!

【问题讨论】:

  • 您是否尝试过不同的position 值,例如autorelative
  • 我做到了,不幸的是,他们使覆盖 div 不适合我想要的整个视口。如果我要声明我的叠加层是可见的而不被切换,那么样式就很好。只有当我添加切换事件时,样式才会改变,我不知道为什么

标签: html css reactjs styled-jsx


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2022-11-23
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    相关资源
    最近更新 更多