材质UI断点以设置方向:纵向和横向视图

时间:2018-09-03 13:08:05

标签: javascript reactjs material-ui responsive

希望能够在Material UI中为平板电脑的样式对象设置纵向和横向视图

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

如何为纵向视图和横向视图添加类似于传统媒体查询的断点:

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

@media screen and (orientation: portrait) {
  body {
    flex-direction: column;
  }
}

3 个答案:

答案 0 :(得分:3)

只需设置类似的内容:

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

答案 1 :(得分:0)

您可以使用以下内容:

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

用于commponet媒体查询将要附加。

答案 2 :(得分:0)

在 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",,
            },
        },
    },
}));