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

szelelaci
  • 163
  • 1
  • 12
  • Does that help? https://stackoverflow.com/questions/56625979/ng-build-base-href-deploy-url-css-background-image-not-worki – David Jun 11 '20 at 19:11

1 Answers1

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);
LogicBlower
  • 1,250
  • 1
  • 8
  • 14