【发布时间】:2022-01-12 01:06:26
【问题描述】:
这是我的示例,我需要将第一个组件放在第二个之前。 目前,尽管 z-index,第二个组件位于第一个组件的前面。我也尝试将样式放在组件标签上,但它不起作用。我的错在哪里?
第一个组件:
import styled from "styled-components";
const Container = styled.div`
position: relative;
display: flex;
justify-content: center;
align-items: center;
height: 500px;
z-index: 100;
`;
function Aaa() {
return (
<Container>asd</Container>
)
}
export default Aaa;
第二个组件
import styled from "styled-components";
const Container = styled.div`
position: relative;
display: flex;
justify-content: center;
align-items: center;
height: 500px;
margin-top: -200px;
background: pink;
z-index: 1;
`;
function Bbb() {
return (
<Container>qwe</Container>
)
}
export default Bbb;
应用:
function App() {
return (
<>
<Aaa />
<Bbb />
</>
);
}
export default App;
【问题讨论】:
标签: css reactjs components z-index