2

Base folder structure is node_modules, public, src.

css file in public folder public/styles.css images are in src/images/icon.png

what should be the correct image path for this image for any class in css file which kept in public folder in localhost eg: .icon { background: url(../src/images/icon.png) no-repeat left top;

images can see directly from http://localhost:3000/exampleimage.png if I have images in public folder.

Please help

2 Answers 2

2

This file path points to a file in the images folder located at the root of the current web

.icon { background: url(/src/images/icon.png) no-repeat left top;}

This file path points to a file in the images folder located in the current folder.

.icon { background: url(src/images/icon.png) no-repeat left top;}

This file path points to a file in the images folder located in the folder one level above the current folder.

.icon { background: url(../src/images/icon.png) no-repeat left top;}
Sign up to request clarification or add additional context in comments.

4 Comments

do you have any live link..?
Sorry. I don;t have any public link
when I copied image to public folder its working as per this path. public/styles.css public/icon.png .icon { background: url(icon.png) no-repeat left top;}
some times image name with different test case dose not support. so please check the name.
1

Your server only serve files within public folder. So that, you have to put files into public folder. In that case, you can use either ./imagefilename.jpg or /imagefilename.jpg to get the file.

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.