0

I'm triying to import an image from my resources folder and then set it as background-image in a div. See what's I'm doing.

import candidatePortrait from "../../../../../images/candidatePortrait.jpg";

<div
    className="candidate-photo"
    style={{
      backgroundImage: props.photo
        ? `url("${props.photo}")`
        : `${candidatePortrait}`
    }}
  />

I know that my folder path is good but I don't know how to set it as backgroundImage. See my div style. Thanks!

4
  • you are using qoutes "" instead of template literals `` Commented Jan 27, 2019 at 16:52
  • I tried it url(${Background}) but not worked Commented Jan 27, 2019 at 16:56
  • Oh no, what the hell, now it's working.. sorry for that, how can I close this? Commented Jan 27, 2019 at 16:57
  • backgroundImage: url(${Background}) Commented Apr 12, 2022 at 17:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.