gpt4 book ai didi

reactjs - 使用 Material ui createStyles

转载 作者:行者123 更新时间:2023-12-04 13:18:02 25 4
gpt4 key购买 nike

我正在尝试将我的 css 从一个 less 文件转换为 Material createStyles,但我无法理解它是如何工作的。

我了解 createstyles 的基础知识,但我的子选择器无法正常工作

我想要的只是能够访问 css 类 missionStatusLibelle

.missionStatus {
display: flex;
align-items: center;
height: 34px;
width: 100%;

.missionStatusLibelle {
align-items: flex-start;
justify-content: flex-start;
margin-left: 10px;
font-size: 14px;
font-weight: 500;
line-height: 20px;
}

}

喜欢

<div className={styles.missionStatusLibelle}>

然后把它改造成这样的

const useStyles = makeStyles((theme: Theme) =>
createStyles({
missionStatus: {
display: "flex",
alignItems: "center",
height: "34px",
width: "100%",

missionStatusLibelle: {
alignItems: "flex-start",
justifyContent: "flex-start",
marginLeft: "10px",
fontSize: "14px",
fontWeight: 500,
lineHeight: "20px"
}
}
}));

但除了使用伪选择器,我无法访问 missionStatusLibelle。

const styles = useStyles();
<div className={styles.missionStatusLibelle}>

最佳答案

你想要像下面这样的东西:

const useStyles = makeStyles((theme: Theme) =>
createStyles({
missionStatus: {
display: "flex",
alignItems: "center",
height: "34px",
width: "100%",

"& $missionStatusLibelle": {
alignItems: "flex-start",
justifyContent: "flex-start",
marginLeft: "10px",
fontSize: "14px",
fontWeight: 500,
lineHeight: "20px"
}
},
missionStatusLibelle: {}
}
));

这是相关文档:https://cssinjs.org/jss-plugin-nested/?v=v10.0.0-alpha.24#use-rulename-to-reference-a-local-rule-within-the-same-style-sheet

关于reactjs - 使用 Material ui createStyles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57871809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com