Todo:在material-ui@v5样式函数中实现同级选择器。
.root + .root {
margin-top: 8px;
}
要实现与material-ui@v4相同的功能,makestyles
非常简单。看看下面的代码:
root: {
width: '100%',
'& + $root': {
marginTop: spacing(1),
},
},
但是我没有成功地使用mui的新api for styled()。我已经尝试了一些替代方法,像这样的东西将生成这样的代码。
const Root = styled(Box)(({ theme: { spacing } }) => ({
[`& + .${Root}`]: {
marginTop: spacing(1),
},
}));
<style data-emotion="css" data-s="">.css-43e1lt+.NO_COMPONENT_SELECTOR{margin-top:8px;}</style>
发布于 2021-11-19 02:52:00
结合情感的兄弟选择器和mui风格的函数,这就是我们可以让它工作的方式。
const Root = styled(Box)(({ theme: { spacing } }) => ({
'& + &': {
marginTop: spacing(1),
},
}));
https://stackoverflow.com/questions/70033666
复制