我正在尝试使用className
更改AppBar组件的样式,但始终遵循.MuiAppBar-root
。
const useBoardStyles = makeStyles((theme: Theme) => ({
appBar: {
backgroundColor: 'red',
color: 'black',
zIndex: theme.zIndex.drawer + 1
},
const classes = useBoardStyles();
...
<AppBar position='fixed' className={classes.appBar} >
此处显示.makeStyles-appBar-139
被.MuiAppBar-colorPrimary
和background-color
的{{1}}覆盖,而color
被.MuiAppBar-root
覆盖。
我也尝试使用z-index
classes
并且仍然相同。
编辑:我正在使用打字稿。
答案 0 :(得分:1)
与默认的“ MuiAppBar-colorPrimary”相比,您的CSS(“ makeStyles-appBar”)似乎最后一次应用了,
针对您的案例的解决方案,
<AppBar position="fixed" style={{ color: 'black', z-index: 1201, background-color: 'red'}}>
appBar: {
backgroundColor: 'red !important',
color: 'black !important',
zIndex: (theme.zIndex.drawer + 1) + ' !important'
}
参考- Transparent AppBar in material-ui (React)
https://material-ui.com/api/app-bar/
import * as React from 'react';
import { withStyles, WithStyles } from 'material-ui/styles';
import { StyledComponent } from 'material-ui';
type C = 'root' | 'foo';
interface P { options?: string[]; }
interface S { open: boolean; }
@withStyles((theme) => ({
root: {},
foo: {},
}))
class Component extends React.Component<P & WithStyles<C>, S> {
render() {
return (
<div className={this.props.classes.root} />
);
}
}
export default Component as StyledComponent<P, C>; // type assertion
const SelectedMenu = withStyles(theme => ({
root: {
maxWidth: 360,
width: '100%',
backgroundColor: theme.palette.background.paper,
},
}))<P>(class extends React.Component<P & WithStyles<C>, S> {