-2

my file structure has 'my site' then 3 html pages, a CSS folder and an images folder. When using the background-image tag in CSS how do I access the images in the folder? i tried background-image: url(images/positive.png, but this did not work.]

Thanks

5
  • it is relative to your css file. Commented Jan 12, 2019 at 19:45
  • @DanielA.White what does that mean? Commented Jan 12, 2019 at 19:45
  • meaning you have to go up a directory then over. Commented Jan 12, 2019 at 19:46
  • stackoverflow.com/a/2718538/5385381 Commented Jan 12, 2019 at 19:46
  • @DanielA.White how would i do this? Commented Jan 12, 2019 at 19:46

3 Answers 3

2

Give this is a try...

background-image: url("../images/your-image-name-here.png");

The "../" basically tells the code that it needs to come out of the CSS folder first, then go into the images folder. Without this step, it is looking for an images folder within the CSS folder.

Sign up to request clarification or add additional context in comments.

Comments

2

The background image is getting fetched from the CSS file. Which means: If your CSS file is located in /Home/style.css and that your background is located at /Home/bg.png, you must specify the following:

background-image url("bg.png");

or:

background-image url("/Home/bg.png");

If the file is located at /bg.png and that your only a folder deep (for example, if your stylesheet is located at /Home/style.css), you can tell the stylesheet to climb up a folder, and then fetch the background, like so:

background-image url("../bg.png");

Hope this helps.

Comments

1

Try this

background-image: url('../images/positive.png');

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.