skip to Main Content

Why is my image aligned center, but not justified? im confused..

<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>

enter image description here

2

Answers


  1. If you want to justify content centred, you have to use "justifyContent: ‘center’" property. Also the "Container" element was having some issues, you can use .

    Check if this what you want to achieve

    <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>
    

    Demo on Codesandbox

    Login or Signup to reply.
  2. You can wrap img with Box

    <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>
    

    Look at my demo here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search