Css 材质UI:不支持的非无单位线高度与栅格对齐。请改用无单位线高度
在许多ReactJs项目中,其中一个错误如下:Css 材质UI:不支持的非无单位线高度与栅格对齐。请改用无单位线高度,css,reactjs,material-ui,Css,Reactjs,Material Ui,在许多ReactJs项目中,其中一个错误如下: Error: Material-UI: unsupported non-unitless line height with grid alignment. Use unitless line heights instead. 在px中定义线宽时,下面是我的代码: const breakpoints = createBreakpoints({}); let theme = createMuiTheme({ typography: {
Error: Material-UI: unsupported non-unitless line height with grid
alignment. Use unitless line heights instead.
在px
中定义线宽时,下面是我的代码:
const breakpoints = createBreakpoints({});
let theme = createMuiTheme({
typography: {
allVariants: {
fontFamily
},
h1: {
fontWeight: 600,
fontSize: 26,
lineHeight: '32px',
[breakpoints.down("sm")]: {
fontSize: 18,
lineHeight: '26px',
}
},
h2: {
fontWeight: 600,
fontSize: 20,
lineHeight: 28 / 20
},
h3: {
fontWeight: 600,
fontSize: 16,
lineHeight: '22px',
[breakpoints.down("sm")]: {
fontSize: 14,
lineHeight: '20px',
}
}
}
})
在上面的示例中,如果我将h1
或h2
的lineHeight
更改为px
值,它会抛出一个错误,但不会为h3
抛出一个错误,而是在px
或无单位值中定义线宽
上面的代码引发错误,因为我在px
中定义了h1
的线宽,如果我将其更改为下面的代码,我将开始工作:
h1: {
fontWeight: 600,
fontSize: 26,
lineHeight: 32 / 26
},
告诉我为什么会这样。我搜索了StackOverflow,但没有找到任何相关问题。可能是您在代码中的某个地方使用了,因为它包含 由于以下原因,
h3
没有发生错误:
if(remFontSize您是否在某处使用responsiveFontSize
?@RyanCogswell,是的,我在排版中使用媒体查询。谢谢,但我没有在我的项目中添加此条件,可能是材质UI正在这样做。我提供了指向材质UI代码中此条件来源的确切位置的链接。它位于responsiveFontSize中s
函数。哦,太棒了,但是为什么material要添加这个条件呢?responsiveFontSizes
使用主题中的初始字体大小作为最大字体大小,然后根据它计算最小字体大小。我想它希望避免产生任何开始时的
if (remFontSize <= 1) {
return;
}