admin管理员组文章数量:1287960
I want to remove the extra space when the second accordion is clicked in material UI. I see that as we click on the second accordion, it moves down but then there is a gap between the first accordion and the second accordion . Can we remove that extra gap when the second accordion opens ?
Here is the link to the codesandbox .
I want to remove the extra space when the second accordion is clicked in material UI. I see that as we click on the second accordion, it moves down but then there is a gap between the first accordion and the second accordion . Can we remove that extra gap when the second accordion opens ?
Here is the link to the codesandbox . https://codesandbox.io/s/yp9lmvwo1x
Share Improve this question edited Mar 25, 2019 at 14:35 kukkuz 42.4k6 gold badges64 silver badges102 bronze badges asked Mar 25, 2019 at 13:55 dfsdiggingdfsdigging 3451 gold badge5 silver badges16 bronze badges 1- this is how it works, you should modify the core library itself. open devtools and check the element to see what class is applied, and if you can change it or not – Amir-Mousavi Commented Mar 25, 2019 at 14:11
2 Answers
Reset to default 7As in the code implementation, it is &$expanded
. So the margin will be applied only when the panel is expanded. but applying some style using expanded option will not override the default margin.
Here's the fix.
const styles = theme => ({
root: {
width: "100%"
},
heading: {
fontSize: theme.typography.pxToRem(15),
fontWeight: theme.typography.fontWeightRegular
},
expanded: {
'&$expanded': {
margin: '4px 0'
}
}
});
Click here to view the solution --> CodeSandbox
Your best bet is to override the default CSS styling with classes. The built in API will help you have conditional styles based on the ponent. More specifically, the docs show the classes you can modify on the Expansion panel.
Using your code sandbox as a reference:
- First you add 'expanded' to your styles
const styles = theme => ({
root: {
width: "100%"
},
heading: {
fontSize: theme.typography.pxToRem(15),
fontWeight: theme.typography.fontWeightRegular
},
expanded: {
margin: "0 auto"
}
});
- Then you specify the CSS on the
<ExpansionPanel />
ponent
...
<ExpansionPanel classes={{ expanded: classes.expanded }}>
...
(Fixed CodeSandbox)
Now it should work as expected, and you can even extend more style by adding to the the object in step one.
本文标签: javascriptRemoving extra space when expansionpanel opens in materialuiStack Overflow
版权声明:本文标题:javascript - Removing extra space when expansion-panel opens in material-ui - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741329866a2372706.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论