扫码关注官方订阅号
为什么我的图像居中对齐,但不两端对齐?我很困惑..
如果您想使内容居中对齐,则必须使用“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
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>
在此处查看我的演示
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
如果您想使内容居中对齐,则必须使用“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>在此处查看我的演示