微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

calc函数的无效属性值错误

如何解决calc函数的无效属性值错误

alc() 中的值必须用空格分隔。

height: "calc(100vh - 4rem)"

解决方法

<App><Header><Content>组件。我正在尝试计算<Content> ie 的高度(应用程序高度 - 标题高度)。

// App.js

import { useStyles } from "./AppStyles";
import Box from "@mui/material/Box";
import Header from "./Header";
import Content from "./Content";

export default function App() {
  const classes = useStyles();
  const { root } = classes;

  return (
    <Box className={root}>
      <Header />
      <Content />
    </Box>
  );
}

// AppStyles.js

import { makeStyles } from "@mui/styles";

export const useStyles = makeStyles((theme) => ({
  root: {
    height: "100vh" // <App> height
  },heading: {
    border: "1px solid blue",height: "4rem" // Height for <content>
  },content: {
    border: "1px solid green",height: `calc(100vh-4rem)`,// Invalid property value
    overflowY: "auto"
  }
}));

height: "calc(100vh-4rem)" 不工作并给出错误,即Invalid property value

// Content.js

import { useStyles } from "./AppStyles";
import Typography from "@mui/material/Typography";

export default function App() {
  const classes = useStyles();
  const { content } = classes;

  return (
    <Typography className={content}>
      Lorem ipsum dolor sit amet,consectetur adipiscing elit. Cras id varius
      sem. Aliquam aliquam leo quis turpis hendrerit dapibus. Mauris ullamcorper
      luctus faucibus. In consectetur,massa at sollicitudin facilisis,velit
      ..
    </Typography>
  );
}

// Header.js

import { useStyles } from "./AppStyles";
import Typography from "@mui/material/Typography";

export default function App() {
  const classes = useStyles();
  const { heading } = classes;

  return <Typography className={heading}>header</Typography>;
}

height: "calc(100vh-4rem)" 不工作并给出错误,即Invalid property value。如何解决这个问题?

CodeSandbox演示。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。