gpt4 book ai didi

html - 如何在 Material UI 中覆盖 css?

转载 作者:太空宇宙 更新时间:2023-11-04 00:53:22 25 4
gpt4 key购买 nike

我正在使用带有 reactjs 的 Material UI。我想覆盖按钮颜色,但在我的情况下,它也会更改选项卡颜色(请参见屏幕截图)如何使用 Material UI 中的主题仅覆盖按钮颜色?代码:

const theme = createMuiTheme({
palette: {
primary: {
main: '#DDB61A',
},
secondary: {
main: '#1d83c6',
},
},
});


<MuiThemeProvider theme={theme}>
<AppBar position="static">
<Tabs value={value} onChange={this.handleTabChange}>
<Tab label="USDT" />
<Tab label="BTC" />
<Tab label="ETH" />
</Tabs>
</AppBar>

{value === 0 && <TabContainer>
<Button variant="contained" color="primary" fullWidth={true}>
Buy/Login
</Button>
</TabContainer>}
</MuiThemeProvider>

第二种方法也行不通:

    const theme = createMuiTheme({
palette: {
myBtn: {
main: '#DDB61A',
}
}
});

<MuiThemeProvider theme={theme}>
<Button variant="contained" color="myBtn" fullWidth={true}>
Buy/Login
</Button>
</MuiThemeProvider>

截图:

enter image description here

最佳答案

您可以使用覆盖自定义组件的样式:

const theme = createMuiTheme({
palette: {
primary: {
main: '#ce93d8', // main color
},
secondary: {
main: '#1d83c6',
},
},
overrides: {
MuiButton: { // Name of the component ⚛️ / style sheet
root: { // Name of the rule
background: '#DDB61A', // Some CSS
},
},
},
});

查看此页面:https://material-ui.com/customization/overrides/

关于html - 如何在 Material UI 中覆盖 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55403352/

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