Alignment issue with React JSX background position; image not centered on the right in Material UI Grid item

I've recently completed a single-page website portfolio, but I'm encountering an issue with setting the background position of the home screen to center right. You can view my site here:

Here is the link to my repository: https://github.com/Bolmstead/Portfolio

I am trying to make the image appear correctly when resizing the window to mobile. I think adjusting the background-position property should solve this problem. The background size is set to cover, and I believe I have implemented it correctly, but it seems like something is missing. Below is the code for my home component:

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>
  );
}

Answer №1

There seems to be a mistake, backgoundPosition should actually be backgroundPosition

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Clicking on the prop in a React class component

This is the situation I am facing <List> {mainTags.map((mainTagItem) => { return ( <ListItem onClick={() => { setMainTag(mainTagItem.tag.tagId) }} button className={classes.mainTagItem}> <div className={classes. ...

Having trouble making class changes with ng-class

I am attempting to change the direction of the arrow in my checkbox by utilizing two classes with the assistance of ng-class. Unfortunately, it is not producing the desired outcome. Below is my code: Note: The angularJS CDN has already been incorporated. ...

Can a div with float: left; be centered?

Currently, I am attempting to create a dock (similar to the iOS dock) for my website. Below is the full code that I have implemented: function addPrevClass(e) { var target = e.target; if (target.getAttribute('src')) { // check if it is img ...

Sorting Contentful posts by date across various Content types

Working on my first project with GatsbyJS and Contentful, I currently have various posts on the website categorized under different Content Models. Let's simplify it by saying there are Photo content types as well as Video Embeds. Using GraphQL to fet ...

Consistently scaling the Embla carousel slides for a seamless presentation experience

In my current project, I am utilizing Embla Carousels and aiming to incorporate a smooth slide scaling effect as users scroll through. The idea is for slides to enlarge the closer they get to the left edge of the carousel container, then decrease in size r ...

What is the process of invoking Link manually in React-router?

I am working on a component that is passed a <Link/> object from react-router as a prop. When the user clicks on a 'next' button within this component, I need to manually trigger the <Link/> object. Currently, I am using refs to acce ...

The MUI DataGrid Pagination has been replaced due to an error: validateDOMNesting(...): <td> should not be nested within a <div>

I'm struggling with replacing the pagination in my DataGrid component from Material-UI. Every time I try, I encounter this console error: Warning: validateDOMNesting(...): <td> cannot appear as a child of <div> I've double-checked my ...

Ways to attach an item using its lower point instead of its upper coordinate

I am currently working on a poker table project using React. As of now, I have player components that need to be strategically positioned around the table. https://i.sstatic.net/gX9Ij.png One challenge I'm facing is that when the screen attribute ch ...

Is there a way to verify the identity of two fields using an external script such as "signup.js"?

My current project involves working with Electron, and it consists of three essential files. The first file is index.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="styles ...

what is the best way to position a glyphicon next to a form?

Forgive me for asking such a basic question, but I struggle with aligning and positioning elements. Here is my issue: https://i.sstatic.net/Uy6XB.jpg https://i.sstatic.net/TTs6V.jpg All I want is for the glyphicon to be displayed next to the textfield, ...

What is the best way to position a component below another component in terms of styling?

Struggling with setting up my React web app using Material-UI. The drawer component is not fitting nicely under the app bar as expected. Despite applying classNames and checking in the console, the styles are not being applied correctly. Currently, the dra ...

Disabling a button based on the state of a switch button using React and Material UI

For the task at hand, we need to ensure that the button is only activated when the switch button's state changes. This state is received as a prop and needs to be validated correctly within the handleChangeState function. const CustomSwitch = ({name, ...

After my data rows are filled, I add jQuery and CSS striping animations to enhance their appearance

Before any click, they have this appearance: Clicking on Sales in the business section reveals a drop-down select box. If I click on "Sales" and modify the text area, it will transition to grey. While the grey rows change accordingly, the black rows shoul ...

What is the best way to ensure the footer is always positioned at the bottom of each page

Hey there, I'm having an issue with printing a large table on my HTML page. I want the footer to appear at the very bottom of every printed page, but so far I haven't found a perfect solution. I came across using tfoot, which prints the footer at ...

Troubleshooting problem with Z-Index conflict in Flash animation

I am facing an issue with two HTML divs - one containing a flash movie and the other simple text. I want to place the textual div on top of the flash movie div, but no matter how I set their positions in CSS or adjust their Z-Index values, the text keeps ...

In the solidgauge feature of Highcharts, the color scheme shifts within a specific range

Is there a way to prevent the color distortion in Highcharts solid gauge charts when increasing the pane size? How can I maintain 100% size without breaking the colors? enter image description here Below is the code snippet: const options = { title: { ...

Positioning icon/image beside the input box

Currently, I have a form with two buttons in a row and an icon (paper clip) that I am attempting to align next to the buttons using UIKit. However, I am facing challenges in getting the alignment right without affecting the size of the elements. Below is a ...

The React front-end struggles to display MongoDB entries and eventually times out after 10 seconds

I am experiencing an issue where my React front-end is unable to fetch details from a MongoDB database and I need assistance debugging the problem. The back-end utilizes a serverless function. Each time I reload the page, my React code fails to locate the ...

5-item carousel in CSS gridView

I'm currently working on a thumbnail slider project. My goal is to display 5 thumbnails at a time, and allow users to move to the next or previous set of thumbnails by clicking on the corresponding buttons. I attempted to modify an existing slider tha ...

The React application encountered an error while trying to read properties of undefined, specifically the 'map' property

Having trouble running this code in React. Any suggestions on how to fix it? return ( <div className="container my-4"> <h1>News Monkey - Top Headlines</h1> <div className="row" ...