简体   繁体   中英

Aligning in CSS and Material UI in React

How do I align one button to the left while the other two on the center?

Pls check codesandbox here CLICK HERE

    <DialogActions sx={{ justifyContent: "center" }}>
      <Button>Left</Button>
      <Button onClick={handleClose}>Cancel center</Button>
      <Button onClick={handleClose}>Subscribe center</Button>
    </DialogActions>

You can achieve that using Grid. Check out below codes.

<DialogActions
  sx={{
    display: "grid",
    gridTemplateColumns: "1fr repeat(2, auto) 1fr",
    justifyContent: "center"
  }}
>
  <Button sx={{ marginRight: "auto" }}>Left</Button>
  <Button onClick={handleClose}>Cancel center</Button>
  <Button onClick={handleClose}>Subscribe center</Button>
</DialogActions>

Set position and left attribute to Left Button.

<Button sx={{ position: "absolute", left: 0 }}>Left</Button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM