LoginSignup
1
2

MUI 実装Tips集

Posted at

※随時更新していきます

要素を画面の真ん中に表示する

return (
  <Box
    display="flex"
    justifyContent="center"
    alignItems="center"
    sx={{width: "100%", height: "100%"}}
  >
    <Container sx={{
      width: "50%", 
      height: "50%", 
      background: "#999009"
    }}>
      <Typography>Center</Typography>
    </Container>
  </Box>
);

image.png

要素の横並び、縦並び

一列に場合は、Stackを使う。
横並びにしたい場合は、directionrowに、縦並びの場合はcolumnを指定

  return (
      <Stack direction={"row"} spacing={2}>
        <Box sx={{ background: "#239999" }}>
          <Typography>Left</Typography>
        </Box>
        <Box sx={{ background: "#239999" }}>
          <Typography>Right</Typography>
        </Box>
      </Stack>
  );

image.png

  return (
      <Stack direction={"column"} spacing={2}>
        <Box sx={{ background: "#239999" }}>
          <Typography>Top</Typography>
        </Box>
        <Box sx={{ background: "#239999" }}>
          <Typography>Bottom</Typography>
        </Box>
      </Stack>
  );

image.png

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2