如何在typescript / MUI中添加zIndex

nkhmeac6  于 2023-03-04  发布在  TypeScript
关注(0)|答案(1)|浏览(109)
    • 嗨,我认为Vercel覆盖了我的css,它在本地工作得很好,但有些样式在Vercel Env上一次也没有应用。因此,当我应用时,背景颜色工作了!重要信息。我现在尝试在zIndex上应用相同的颜色,但它不工作。请协助**

类型"${number} !important"不能赋给类型"ZIndexProperty|属性函数〈(值:JSS字体,索引:编号,数组:JSSFontface [])=〉未知,ZIndexProperty〉'。类型' string '不能赋给类型' ZIndexProperty|属性函数〈(值:JSS字体,索引:编号,数组:JSSFontface [])=〉未知,ZIndexProperty〉'。类型"${number} !important"不能分配给类型"" auto ""。类型"string"不能分配给类型"" auto ""

const drawerWidth = 280;
const useStyles = makeStyles((theme: Theme) =>
  createStyles({
    root: {
      display: 'flex'
    },
    appBar: {
      zIndex: `${theme.zIndex.drawer + 1} !important`,
      transition: theme.transitions.create(['width', 'margin'], {
        easing: theme.transitions.easing.sharp,
        duration: theme.transitions.duration.leavingScreen
      }),
      backgroundColor: `${theme.palette.secondary.contrastText} !important`,
      height: 80,
      paddingTop: theme.spacing(2),
      display: 'flex',
      flexDirection: 'column',
      justifyContent: 'center'
    },```
zwghvu4y

zwghvu4y1#

为什么用!重要吗?试着这样问:

import {makeStyles, Theme} from '@material-ui/core';

export const useStyles = makeStyles((theme: Theme) => ({
  appbar: {
    zIndex: theme.zIndex.drawer + 1,
  },
}));

并使用:

import { AppBar as MuiAppBar, Toolbar } from '@material-ui/core';
import { useStyles } from "./Appbar.styles";

const Appbar: FC = ({ children }) => {

  const classes = useStyles()

  return (
    <MuiAppBar position="fixed" className={classes.appbar}>
      <Toolbar>{children}</Toolbar>
    </MuiAppBar>
  );
};

export default Appbar;

相关问题