12

Would like to be able to set portrait and landscape views on the styles object for tablets in Material UI

const styles = theme => ({
  root: {
    padding: theme.spacing.unit,
    [theme.breakpoints.up('md')]: {
      backgroundColor: theme.palette.secondary.main
    }
  }
}

how can i add breakpoints for portrait view and landscape view similar to the traditional media query:

@media screen and (orientation: landscape) {
  body {
    flex-direction: row;
  }
}

@media screen and (orientation: portrait) {
  body {
    flex-direction: column;
  }
}
Julio Cornelio
  • 171
  • 1
  • 2
  • 6

3 Answers3

10

Just set something like that:

const styles = theme => ({
  root: {
    padding: theme.spacing.unit,
    [`${theme.breakpoints.up('md')} and (orientation: portrait)`]: {
      flexDirection: 'column'
    }
  }
}
4

You're able to use something like this:

'@media (orientation: landscape)': {
  flexDirection: `orientation`,
},

for the component media query will be attached.

0

Used this in version 4.11.1

const useStyles = makeStyle((theme) =>({
    container:{
        border:"1px dashed red",
        [theme.breakpoints.down("md")]{
           border: "1px solid blue",
           '@media (orientation: landscape)': {
              border: "1px solid green",,
            },
        },
    },
}));
Hillsie
  • 607
  • 1
  • 6
  • 15