【发布时间】:2022-01-17 21:36:30
【问题描述】:
假设我有以下 @font-face 规则,我想将它们作为 CSSObject 而不是扁平字符串。
@font-face {
font-family: 'Blah';
font-weight: 400;
font-style: normal;
src:
url('./Blah-Normal.woff2') format('woff2'),
url('./Blah-Normal.woff') format('woff');
}
@font-face {
font-family: 'Blah';
font-weight: 700;
font-style: bold;
src:
url('./Blah-Bold.woff2') format('woff2'),
url('./Blah-Bold.woff') format('woff');
}
...
如何将其定义为CSSObject?我正在尝试将其传递给 Mui 的MuiCssBaseline,它需要CSSObject 或string。我想传递一个CSSObject,以便我可以更轻松地在其上添加更多 CSS 样式并且更易于阅读。但现在它只是一个仅包含 @font-face 定义的扁平字符串。
// import { CSSObject } from '@mui/material';
// import { CSSObject } from '@emotion/styled';
import { CSSObject } from 'styled-components';
const BlahCSSObject = {
'@font-face': {
// magic?
src: [
// it definitely don't like the following format
url('./Blah-Bold.woff2') format('woff2'),
url('./Blah-Bold.woff') format('woff')
]
},
'@font-face': { // would cause dupe keys no?
...
},
...
} as CSSObject;
谢谢!
【问题讨论】:
标签: css reactjs fonts styled-components emotion