1

I have an image and i need to make it cover all of the background.

The problem is, that for some reason the image isn't covering all of the background, and it always stops somwhere where i put another object, and never goes farther then this.

Im using material ui and my code looks like this

import { Image } from "../images";
import { TextField } from "@mui/material";

const useStyles = makeStyles({
Background: {
    display: "flex",
    alignItems: "center",
    justifyContent: "center",
    justifyItems: "center",
    flexDirection: "row-reverse",
    width: "100%",
    height: "100%",
    backgroundImage:  `url(${Image})`,
    backgroundSize: "cover",
    backgroundRepeat: 'no-repeat',
    backgroundPosition: '50% 10%',
  }
})

function Login() {
  const classes = useStyles();

  return (
    <div className={classes.Background}>
       <TextField></TextField>
    </div>
  );
}

This is the result i get:

3
  • Codesandbox link ? Commented Jun 1, 2022 at 12:26
  • doesn't have one, and unfortunately, it requires a lot to open a react project there rn. that's why i've brought here the entire code. is there a specific thing you wanted to check that i didn't bring here? Commented Jun 1, 2022 at 13:18
  • ok wait, i found out a way to do that. here's the link: codesandbox.io/s/dazzling-perlman-vggskp?file=/src/App.js Commented Jun 1, 2022 at 13:22

1 Answer 1

1

Try this style

Background: {
    display: "flex",
    alignItems: "center",
    justifyContent: "center",
    justifyItems: "center",
    flexDirection: "row-reverse",
    width: "100%",
    height: "100vh",
    backgroundImage: `url(${asd})`,
    backgroundSize: "cover",
    backgroundRepeat: "no-repeat",
    backgroundPosition: "50% 10%"
  }



Sign up to request clarification or add additional context in comments.

2 Comments

setting the backgroundSize as "cover" didn't help :(
I have added height: "100vh",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.