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>
);
}
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With