1

How to specify path to images in css styles for component?

My styles are stored in assets directory, but components in others. When I try to set full path it is so long.

Sample is:

background: url(../../assets/img/angularclass-avatar.png)
2
  • This seems to be the right way to set the path Commented Jul 24, 2017 at 6:27
  • Can I set constant like this: PATH = ../../assets/img/ and use only angularclass-avatar.png? Commented Jul 24, 2017 at 6:29

1 Answer 1

5

It should be

background: 'url(/assets/img/angularclass-avatar.png);'
Sign up to request clarification or add additional context in comments.

8 Comments

Also I can define variable in SASS and just pust it everywhere
Is there no way to make the relative path work as is?
@user987949, it depends where the resources are. But the relative path is not the issue
When I use a relative path in CSS I get a build error: With this: ERROR in ./src/styles.css Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
@user987949 Where is /images relative to /app or /src?
|

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.