Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align typography component to the right

I would like to align two typography components on the same line so that one is aligned to the left and the other to the right. How do I achieve this?

This is the code I have but the components are aligned next to each other to the left.

const useStyles = makeStyles({
  leftText: {
    textAlign: "left"
  },
  rightText: {
    textAlign: "right"
  }
});

function ChooseNewSupport(props) {
    const classes = useStyles();
    return (
        <DialogContent>
        <Typography inline variant="body1" className={classes.leftText}>
          Choose New Support:
        </Typography>
        <Typography inline variant="body1" className={classes.rightText}>
    </DialogContent>
    );
}
like image 758
user2260199 Avatar asked May 22 '19 02:05

user2260199


People also ask

How do you align content to right in material UI?

To align a component to the center or right with React Material UI, we can add a flex container with the Grid component. We add the Grid component and add the container prop to make it a flexbox container. Then we set the justify prop to flex-end to align the child components on the right side.


1 Answers

If you're using Mui, why not use their props - it'll keep it easier then your own styles. You will also have to put the p elements within a div - if you use Grid you can use flex box "space-between" to push each element to either side.

<Grid container justify="space-between">  
  <Typography inline variant="body1" align="left">Choose New Support:</Typography>
  <Typography inline variant="body1" align="right">some text</Typography>
</Grid>
like image 118
M.Lewis Avatar answered Sep 26 '22 03:09

M.Lewis