【问题标题】:ReactJS: Material ui breakpointsReactJS:材质 ui 断点
【发布时间】:2019-02-28 06:55:49
【问题描述】:

breakpoints.upbreakpoints.downbreakpoints.betweenbreakpoints.value 之间有什么区别? 这段代码是什么意思,断点值是如何在这里工作的?是theme.spacing.unit*2*2 = theme.spacing.unit*4还是有别的意思?

[theme.breakpoints.up(600 + theme.spacing.unit * 2 * 2)]: {
  width: 600,
  marginLeft: 'auto',
  marginRight: 'auto',
},

【问题讨论】:

  • [theme.breakpoints.up(600 + theme.spacing.unit * 2 * 2)]没有特殊意义
  • theme.spacing.unit * 4。我刚刚发布了一个答案,其中解释了您提到的各种断点方法。如果它回答了您的问题,请告诉我。

标签: reactjs responsive-design media-queries material-ui breakpoints


【解决方案1】:

Material 使用以下一组断点。您可以在主题中自定义此断点的

Breakpoint documentation

断点是具有特定布局要求的预定屏幕尺寸范围。

  • xs(超小):0px 或更大
  • sm(小):600 像素或更大
  • md(中等):960 像素或更大
  • lg(大):1280 像素或更大
  • xl(超大):1920 像素或更大

您询问的函数(updownbetween)是使用主题中定义的断点创建媒体查询的助手。

注意:breakpoints.up()breakpoints.down() 也接受一个数字,该数字将转换为像素。这不适用于其他方法。

breakpoints.up(断点|数字)

创建一个 min-width 媒体查询,以大于或等于给定断点的屏幕尺寸为目标。

// Styles will be applies to screen sizes from "sm" and up
[theme.breakpoints.up('sm')]: {
  // styles
}

breakpoints.down(断点|数字)

采用断点名称并创建 ma​​x-width 媒体查询,目标屏幕尺寸最大为并包括给定断点。

因为这是包容性的,所以 max-width 将是下一个断点的值。

// Styles will be applies to screen sizes from 0 up to and including "md"
[theme.breakpoints.down('md')]: {
  // styles
}

breakpoints.between(start, end)

采用两个断点名称,并创建一个媒体查询,以从第一个断点到并包括第二个断点的屏幕尺寸为目标。

// Styles will be applies to screen sizes from "sm" up to
// and including "lg"
[theme.breakpoints.between('sm', 'lg')]: {
  // styles
}

breakpoints.values

包含主题中定义的断点值的对象

{xs: 0, sm: 600, md: 960, lg: 1280, xl: 1920}

breakpoints.width(断点)

该函数用于获取特定断点的值。

theme.breakpoints.width('sm')  // => 600

【讨论】:

  • 谢谢卢克!但为什么是 (600 + theme.spacing.unit*4) 而不仅仅是 (600)?这段代码sn-p取自materialui源码。
  • 你知道它在什么文件里吗?
  • Material-UI 使用8 point grid 进行布局和间距...
  • theme.spacing.unit (8) 是布局网格的基本单位。所以所有的边距/填充等都是theme.spacing.unit 的倍数。那个代码 sn-p 是一个 600px 加 16px * 2 的媒体查询,这可能是为了考虑左/右边距/填充。
  • 谢谢卢克!我理解了这个概念。这实际上意味着如果屏幕尺寸低于 breakpoints.up 的值,则指定的 padding 和 margin 都不适用。
猜你喜欢
  • 1970-01-01
  • 2017-09-20
  • 1970-01-01
  • 1970-01-01
  • 2020-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多