【发布时间】:2022-08-09 19:58:13
【问题描述】:
有谁知道如何将多个 CSS 类与 MUI 5 SX 道具一起使用?我创建了一个基类,我想将它与我的 Box 组件一起使用,但使用第二个类专门用于 Box 内的文本。应用基类,例如 sx={styles.baseBoxStyle} 有效,但 sx={styles.baseBoxStyle styles.customBoxFontStyle} 返回错误。下面提供了完整的代码 sn-p 和沙箱。非常感谢任何帮助!
沙盒:https://codesandbox.io/s/mui-5-styling-uqt9m?file=/pages/index.js
import * as React from \"react\";
import Box from \"@mui/material/Box\";
const styles = {
baseBoxStyle: {
backgroundColor: \"red\",
borderRadius: \"20px 20px 20px 20px\",
border: \"1px solid black\",
maxWidth: \"150px\",
margin: \"20px\",
padding: \"10px\"
},
customBoxFontStyle: {
color: \"yellow\",
fontWeight: \"bold\"
}
};
export default function Index() {
return <Box sx={styles.baseBoxStyle styles.customBoxFontStyle}>This is a test</Box>;
}
-
你好,如果我想在样式中使用主题并通过它,我该如何使用它?
标签: javascript reactjs material-ui