简体   繁体   中英

Resolving assets path in css with Angular 7 cli

I have an image (toolbar-bg.svg) in my assets folder, and trying to set it as the background image for an element. If I apply background: url('assets/toolbar-bg.svg') then it won't build because postcss can't resolve the file, but if I apply background: url('../assets/toolbar-bg.svg') it builds but then the path is wrong client side and it can't load the image. How do I get this to work properly?

Try These pathes

  1. background: url('~/assets/toolbar-bg.svg')
  2. background: url('/assets/toolbar-bg.svg')

If none of them worked then you better try physical adresses

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM