我希望在Material UI中点击第二个手风琴时,能够去除额外的空间。当我们点击第二个手风琴时,它会向下移动,但是第一个手风琴和第二个手风琴之间会出现间隙。
我们能否在第二个手风琴打开时去除这个额外的间隙?这里是codesandbox的链接。
https://codesandbox.io/s/yp9lmvwo1x
在代码实现中,使用的是&$expanded
。因此,当面板扩展时才会应用边距,但使用expanded
选项应用一些样式不会覆盖默认边距。
这是修复方法。
const styles = theme => ({
root: {
width: "100%"
},
heading: {
fontSize: theme.typography.pxToRem(15),
fontWeight: theme.typography.fontWeightRegular
},
expanded: {
'&$expanded': {
margin: '4px 0'
}
}
});
点击此处查看解决方案 --> CodeSandbox
const styles = theme => ({
root: {
width: "100%"
},
heading: {
fontSize: theme.typography.pxToRem(15),
fontWeight: theme.typography.fontWeightRegular
},
expanded: {
margin: "0 auto"
}
});
<ExpansionPanel />
组件上指定 CSS。...
<ExpansionPanel classes={{ expanded: classes.expanded }}>
...