【发布时间】:2019-06-06 22:43:02
【问题描述】:
我为使用 JSS 的 React 项目创建了一个全局样式表。我对 CSS、SASS 和 CSS 模块非常熟悉,但这是我第一次使用 JSS。
标题都将具有相同的边距。出于可维护性和性能的原因,我不想将它键入多种类型或让它多次出现在编译样式中。我也希望不必为所有标题添加一个类。
由于选择器数组([h1,h3,h4,h5,h6]),我的 JSS 不起作用:
const globalStyles = theme => ({
'@global': {
body: {
fontFamily: ['Roboto', 'sans-serif'].join(','),
},
[h1, h3, h4, h5, h6]: {
margin: '0 0 .35em 0'
},
h1: {
fontSize: theme.typography.pxToRem(40),
fontWeight: 600
},
h3: {
fontSize: theme.typography.pxToRem(34),
lineHeight: 1.75
},
h5: {
fontSize: theme.typography.pxToRem(28),
lineHeight: 'normal'
},
h6: {
fontSize: theme.typography.pxToRem(20),
lineHeight: 'normal'
}
}
})
export default globalStyles
我正在尝试实现以下输出:
body {
font-family: Roboto, sans-serif
}
h1, h3, h4, h5, h6 {
margin: 0 0 .35em 0
}
h1 {
font-size: 2.5rem;
font-weight: 600;
}
h3 {
font-size: 2.125rem;
line-height: 1.75;
}
h5 {
font-size: 1.75rem;
line-height: normal;
}
h6 {
font-size: 1.25rem;
line-height: normal;
}
JSS 可以做到这一点吗?我在 JSS 上做了一些阅读,但我没有找到解决方案。
【问题讨论】:
标签: javascript reactjs jss