【问题标题】:React JSX background position not placing image to center right in Material UI Grid itemReact JSX背景位置没有将图像放置在Material UI Grid项目中的中心右侧
【发布时间】:2021-07-01 18:01:00
【问题描述】:

我刚刚创建了一个单页网站组合,它非常完整,但是在将主屏幕的背景位置设置为右中时存在问题。这是我的网站:

https://berkley-portfolio.netlify.app/

我的仓库:https://github.com/Bolmstead/Portfolio

我只想在将窗口大小调整为移动设备时出现我的图像。我相信背景位置会解决这个问题吗?背景大小是封面,我相信我做对了,但似乎遗漏了一些东西。以下是我的家庭组件:

import React, {  useEffect } from "react";
import Grid from "@material-ui/core/Grid";
import Typography from "@material-ui/core/Typography";
import { makeStyles } from "@material-ui/core/styles";
import Container from "@material-ui/core/Container";


const useStyles = makeStyles((theme) => ({
  homeContainer: {
    backgroundImage: `url(/images/home2.jpg)`,
    height: "103vh",
    backgroundSize: "cover",
    backgoundPosition: "center right"
  },
  overlay: {
    zIndex: 1,
    height: "100%",
    width: "100%",
    backgroundSize: "cover",
    background: "rgba(0, 0, 0, 0.5)",
  },
  firstName: {
    fontWeight: "bold",
    color: "white"
  },
  lastName: {
    fontWeight: "bold",
    color: "#FFC220"
  },
  caption: {
    fontWeight: "bold",
    color: "white"
  },
}));

export default function Home() {
  const classes = useStyles();
  const [fadedIn, setFadedIn] = React.useState(false);

  useEffect(() => {
    async function fadeInHomeScreen() {
      setFadedIn((prev) => !prev);
    }
    fadeInHomeScreen();
  }, []);

  return (
    <Grid item xs={12} className={classes.homeContainer}>
      <a id="Home">
        
      <Grid
        container
        alignItems="center"
        justify="center"
        direction="row"
        className={classes.overlay}
      >
        <Grid item xs={12} align="center" justify="center">
          <Container maxWidth="md" align="center" justify="center" className={classes.container}>
            <Typography
              m={12}
              variant="h2"
              component="h2"
              className={classes.firstName}
              display="inline"
            >
              Berkley{" "}
            </Typography>
            <Typography
              m={12}
              variant="h2"
              component="h2"
              className={classes.lastName}
              display="inline"
            >
               Olmstead
            </Typography>
            <Typography
              m={12}
              variant="h6"
              component="h6"
              className={classes.caption}
            >
              I'm a Full-Stack Developer
            </Typography>
          </Container>
        </Grid>       
      </Grid>
      </a>
    </Grid>
  );
}

【问题讨论】:

    标签: css reactjs material-ui jsx


    【解决方案1】:

    你打错了,backgoundPosition 应该是backgroundPosition

    homeContainer: {
      backgroundImage: `url(/images/home2.jpg)`,
      height: "103vh",
      backgroundSize: "cover",
      backgroundPosition: "center right"
    },
    

    【讨论】:

    • 我当然知道。非常感谢!不知道我是怎么错过的
    猜你喜欢
    • 2010-10-04
    • 2020-05-21
    • 2021-10-25
    • 2021-09-12
    • 2015-09-18
    • 2011-03-12
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    相关资源
    最近更新 更多