Set css background image in phpstorm - "cannot resolve file"

I have an image that I would like to set as a background in a Laravel 3 project - background-image: url("public/img/find-a-table.png");

But he says that “cannot resolve find-a-table.png” in phpStorm , although I definitely have an image file added to this directory.

Do I need to change something to find his image in this directory? In any other regular web application this would be pretty trivial, so I don’t know if something is missing.


Does this site show that I don’t need quotes around the path? I tried too, but this does not fix. They use:

background: url(images/bg.jpg) no-repeat center center fixed; without quotes

+5
source share
4 answers

phpStorm does not tell you that your browser will not see this file. It just reports that phpStorm itself does not see the file.

You must tell phpStorm where the starting path of the relative path is.

To do this, open the project file structure ( cmd + 1 on Mac), right-click your (public) root directory ( public ), then Mark Directory As > and Mark as Sources Root . After a couple of seconds, the error message should disappear.

+7
source

Keep in mind that the image path must be relative to your css or absolute if it starts with / .

Try background-image: url("/img/find-a-table.png"); Or is it background-image: url("../img/find-a-table.png"); if your css folder is next img

You probably don't need public/ in your url. And don't rely on phpstorm with this, test it in a browser.

+3
source

Was there the same error in my WebStorm IDE that was resolved by adding "../" to the path. try the following:

 background-image: url("../img/find-a-table.png"); 
+1
source

Here is the fix:

1- Right-click on your (publicly accessible root directory) where you are using image sources from.

2- Scroll down to Mark directory as

3- Select Resource Root

enter image description here

+1
source

All Articles