简体   繁体   中英

Styling a react component in styled-component

I am trying to align the component in the center. But I am unable to do so.

Component snippet:

<Grid item xs={12}>
              <Box marginTop={2} marginBottom={2} display="flex">
                <Box width="100%">
                  <Divider />
                </Box>
                <Box width="100%">
                  <OrLabel>OR</OrLabel>
                </Box>
                <Box width="50%">
                  <Divider />
                </Box>
              </Box>
            </Grid>

component styling:

export const OrLabel = styled.span`
  position: absolute;
  margin-top: -10px;
  margin-left: -10px;
`;

在此处输入图像描述

I tried the position: center in the styled-component, but it also giving the same result. How could I move the "OR" to the center?

please try it:

 <Box style{{display:"flex",alignItem:"center",justyfyContent:"center"}} width="100%"> <OrLabel>OR</OrLabel> </Box>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM