Ad
Button Next To Typography
How can I place a button next to typography tag inside a paper container, aligned to right/end?
<div className={classes.root}>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<Paper className={classes.paper}>
<Typography inline>CPU</Typography>
<IconButton className={classes.button} aria-label="Add" size="medium" ><AddIcon /></IconButton>
</Paper>
</Grid>
</div>
Here my styles:
const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
padding: theme.spacing(2),
flexGrow: 1,
},
paper: {
padding: theme.spacing(2),
color: theme.palette.text.secondary,
}
}));
I'm using the inline attribute of Typography but the button keep going on the next line...many thanks, I'm a newbie.
Ad
Answer
If you don't mind adding more dom elements.
<div className={classes.root}>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<Paper className={classes.paper}>
<Grid container alignContent="space-between" alignItems="center">
<Grid item>
<Typography inline>CPU</Typography>
</Grid>
<Grid item>
<IconButton className={classes.button} aria-label="Add" size="medium" ><AddIcon /></IconButton>
</Grid>
</Grid>
</Paper>
</Grid>
</div>
Otherwise you can just change CSS propertie
paper: {
padding: theme.spacing(2),
color: theme.palette.text.secondary,
display: flex,
alignContent: 'space-between',
alignItems: 'center'
}
Ad
source: stackoverflow.com
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?
Ad