Skip to content

Instantly share code, notes, and snippets.

@daveteu
Created August 27, 2020 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveteu/299eb16f6600d44c4a26c2d3e4db66a1 to your computer and use it in GitHub Desktop.
Save daveteu/299eb16f6600d44c4a26c2d3e4db66a1 to your computer and use it in GitHub Desktop.
Simple way to display text in the middle of 2 horizontal lines in Material-Ui
import { Grid, Divider, Typography } from '@material-ui/core'
//Could use makeStyles here but it's harder to understand
const MidText = ({text}) => {
return ( <div style={{ padding: '8px' }}>
<Grid container>
<Grid item style={{ flex: 1, display: 'flex', alignItems: 'center'}}>
<Divider style={{ flexGrow: 1 }}/>
</Grid>
<Grid item>
<Typography style={{ paddingLeft: '20px', paddingRight: '20px'}}>{text}</Typography>
</Grid>
<Grid item style={{ flex: 1, display: 'flex', alignItems: 'center'}}>
<Divider style={{ flexGrow: 1 }}/>
</Grid>
</Grid>
</div>)
}
export default MidText
@daveteu
Copy link
Author

daveteu commented Aug 27, 2020

image

Fully responsive with the use of material-ui grid and flex grow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment