为什么我的图像居中对齐,但不两端对齐?我很困惑..
<Box
sx={{
display: 'flex',
minHeight: '100vh',
alignItems: 'center',
flexGrow: 1,
}}>
<Container maxWidth="sm">
<img src="https://static.vecteezy.com/system/resources/previews/001/200/294/original/house-png.png"
width={200}
alt="img"
/>
<LinearProgress sx={{ mt: 4 }} />
</Container>
</Box> Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
如果您想使内容居中对齐,则必须使用“justifyContent: 'center'”属性。另外,“Container”元素存在一些问题,您可以使用 。
检查这是否是您想要实现的目标
<Box sx={{ display: "flex", minHeight: "100vh", alignItems: "center", justifyContent: "center", flexGrow: 1 }} > <Box> <img src="https://static.vecteezy.com/system/resources/previews/001/200/294/original/house-png.png" width={200} alt="img" /> <LinearProgress sx={{ mt: 4 }} /> </Box> </Box>Codesandbox 上的演示
您可以用
Box包裹img<Box sx={{ display: 'flex', minHeight: '100vh', alignItems: "center", flexGrow: 1, }} > <Container maxWidth="sm"> <Box sx={{ display: 'flex', justifyContent: "center" }} > <img src="https://static.vecteezy.com/system/resources/previews/001/200/294/original/house-png.png" width={200} alt="img" /> </Box> <LinearProgress sx={{ mt: 4 }} /> </Container> </Box>在此处查看我的演示