【发布时间】: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值,例如auto或relative? -
我做到了,不幸的是,他们使覆盖 div 不适合我想要的整个视口。如果我要声明我的叠加层是可见的而不被切换,那么样式就很好。只有当我添加切换事件时,样式才会改变,我不知道为什么
标签: html css reactjs styled-jsx