【问题标题】:Material UI breakpoints to set orientation: portrait and landscape viewMaterial UI 断点设置方向:纵向和横向视图
【发布时间】:2019-02-08 13:12:25
【问题描述】:

希望能够在 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;
  }
}

【问题讨论】:

  • 你遇到了什么问题?

标签: javascript reactjs material-ui responsive


【解决方案1】:

只需设置类似的东西:

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

【讨论】:

    【解决方案2】:

    你可以使用这样的东西:

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

    对于组件媒体查询将附加。

    【讨论】:

    • 只记住这条规则,应该作为一个单独的元素而不是作为一个嵌套元素。
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-23
      相关资源
      最近更新 更多