【发布时间】:2021-01-21 04:08:32
【问题描述】:
我正在为我的 react 应用程序使用从 Figma 到 CSS 的 UI。目前,我正在尝试制作 3 层 div(分别为 className:'a'、'b'、'c'),它们彼此重叠,div 'a' 在底部,然后是 'b' ,然后是顶部的“c”。它们都共享一个父 div。
现在我没有设置 div 'a' 位置,'b' 和 'c' 都设置为位置 'absolute',z-index 分别为 1 和 2。除非我更改了屏幕尺寸,否则它工作正常。当我扩大屏幕时,div 'b' 和 'c' 都开始向右移动。我试图将它们更改为“固定”或“相对”位置,但也没有用。 下面是我的 react 组件和 css。
//react component
const Zoom = () => {
return (
<div>
<BackgroundImage className='a' />
<PromptBox className='b'/>
<Link to="/zoom">
<Button className='c' />
</Link>
</div>
);
};
//css
.a {
width: 895px;
height: 393px;
left: 3px;
top: 13px;
}
.b {
position: absolute;
left: 25.56%;
right: 25.89%;
top: 8.15%;
bottom: 19.16%;
filter: drop-shadow(0px 4px 4px rgba(0, 0, 0,
0.25));
}
.c {
cursor: auto;
position: absolute;
left: 40.04%;
right: 18.3%;
top: 25.25%;
bottom: 68.61%;
}
【问题讨论】:
-
查看以下内容 -
left: 50%, transform: translate(-50%): w3.org/Style/Examples/007/center.en.html#hv3