2

I am building my angular app with ng build --deploy-url="/foo/bar/" and trying to display background images using css background: url("url");, but in the browser's dev tool I see incorrect url when it is trying to get the image.

if I try with: background: url("assets/img/img.svg") or background: url("./assets/img/img.svg") the request in the browser looks like: http://localhost:38080/foo/bar/img.svg So /assets/img/ disapears.

if I try with: background: url("/assets/img/img.svg") the request in the browser looks like: http://localhost:38080/assets/img/img.svg Which is kind of expected, but who knows I tried..

Any idea? Thanks in advance

1

1 Answer 1

0

give the url without quote it will take care and resolve.

background: url(./assets/img/img.svg)

in my project i do it like at top of scss file

  $svg-relative-part: "./../../../../assets/svg/";
  $grey-close: 'grey.svg';
  background: url($svg-relative-part + $grey);
Sign up to request clarification or add additional context in comments.

Comments

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.