I'm trying to center an item on the screen using material ui, but it's appearing at the top instead of the middle. How can I fix this?
import * as React from 'react';
import Box, { BoxProps } from '@mui/material/Box';
function Item(props: BoxProps) {
const { sx, ...other } = props;
return (
<Box
sx={{
p: 1,
m: 1,
bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : 'grey.100'),
color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'),
border: '1px solid',
borderColor: (theme) =>
theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300',
borderRadius: 2,
fontSize: '0.875rem',
fontWeight: '700',
...sx,
}}
{...other}
/>
);
}
export default function JustifyContent() {
return (
<div style={{ width: '100%', height:'100%'}}>
<Box
sx={{
display: 'flex',
justifyContent: 'center',
textAlign:'center',
p: 1,
m: 1,
bgcolor: 'background.paper',
borderRadius: 1,
}}
>
<Item>Item 1</Item>
</Box>
</div>
);
}
What am I doing wrong in my code?