为什么我的图像居中对齐,但不两端对齐?我很困惑..
<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>
P粉5485126372023-09-09 12:34:07
如果您想使内容居中对齐,则必须使用“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>
P粉6804879672023-09-09 09:42:29
您可以用 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>