首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在makeStyles钩子中使用props.theme.breakpoints?

如何在makeStyles钩子中使用props.theme.breakpoints?
EN

Stack Overflow用户
提问于 2019-07-24 06:57:18
回答 2查看 3K关注 0票数 2

因此,我尝试使用这里给出的材料断点https://material-ui.com/customization/breakpoints/和makeStyles钩子。我无法使用props.breakpoints.down('600')进行响应式样式设置。如何在makeStyles钩子中使用断点?

代码语言:javascript
复制
  bottom: '64px',
  height: '54px',
  backgroundImage: 'none',
  color: 'red'
}

我试过了,但就是不管用。

代码语言:javascript
复制
export const useStyles = makeStyles({
  Container: {
    position: 'absolute',
    zIndex: '5',
    bottom: '0',
    paddingTop: ' 1%',
    left: ' 0',
    zIndex: '10',
    width: '100vw',
    backgroundImage: 'linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(45, 49, 55, 0.81))',
    display: 'block',
    // height: "74px"
    height: props => props.captionHeight,
    [props => props.breakpoints.down('600')]: {
      bottom: '64px',
      height: '54px',
      backgroundImage: 'none',
      color: 'red'
    }
  }});

I expect to be able to have apply the styles when the screenwidth is lesser than 600px using the material-ui breakpoints api.
EN

回答 2

Stack Overflow用户

发布于 2020-10-28 19:12:31

您可以使用主题的“断点”属性来指定断点。在此示例中,当窗口宽度超过600px时,您将获得背景颜色属性为蓝色。

以下是代码沙箱中的工作示例:https://codesandbox.io/s/eager-benz-697f2?fontsize=14&hidenavigation=1&theme=dark

代码语言:javascript
复制
const useStyles = makeStyles(theme => ({
    s1: {
        backgroundColor: 'red',
        [theme.breakpoints.up('600')]: {
            backgroundColor: 'blue'
        }
    },
    s2: {
        backgroundColor: 'green'
    }
}));
票数 2
EN

Stack Overflow用户

发布于 2019-07-24 08:01:09

找到答案了。

代码语言:javascript
复制
export const useStyles = makeStyles(theme => {})

成功了!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57173195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档