Rahul Shah
Rahul Shah

Reputation: 71

backgroundImage path for css from public folder not working after build in reactjs

I have added image path from public folder in App.css

It's working in local but not working after generating a build.

You may access my code on codesandbox at below path:

https://codesandbox.io/s/reactimagepath-sjtri

Please check and guide me towards solution.

Upvotes: 0

Views: 4291

Answers (2)

akhtarvahid
akhtarvahid

Reputation: 9779

Move your images folder inside src folder

src/images/texture.jpg

and replace your background-image: url("./images/texture.jpg");

or background-image: url("../images/texture.jpg");

.App {
  font-family: sans-serif;
  text-align: center;
  background-image: url("./images/texture.jpg");  // or url("../images/texture.jpg");
  min-height: 100vh;
  background-repeat: no-repeat;
  background-size: cover;
}

Reference- when to use public folder reactjs recommendation

Upvotes: 1

meDeepakJain
meDeepakJain

Reputation: 154

Try modifying your css like this:

.App {
  font-family: sans-serif;
  text-align: center;
  background-image: url("./images/texture.jpg");
  min-height: 100vh;
  background-repeat: no-repeat;
  background-size: cover;
}

Upvotes: 0

Related Questions