Cannot resolve directory in CSS files


Разработка ведется через SVN, файлы правятся на локальной машине, потом заливаются на тестовый сервак.

При редактировании css-файла и указания пути вида /img/pic.png WebStorm подсвечивает такой url как неверный. При подключении js/htc файла, все нормально и такие файлы "находятся". Подробнее на скриншотах.
Подскажите что не так и как исправить такое?


Hi Denis,

If that image file definitely exist on your PC then it looks like you need to mark the folder that contains img subfolder as Resource Root at File | Settings | Directories.


Hi Andriy.
Thanks. It's resolve a problem.


Hi! I have the similar issue.

My project is one of the projects on the site. So url to image looks like:

In my css file I use rule like:
a { background: url(/myproject/images/image.png) }

My project structure is looks like that:

Webserver uses "web" as a site root.

I've setup "web" as as Resources folder, but "/myproject/images/image.png"  can't be found there because this folder not contains a subfolder "myproject". And code inspector make this url underlined.

Please help me to solve this problem


Hi there,

I'm not sure that anything can be done here from IDE side only -- currently IDE does not support this kind of "setup". You can try disabling this inspection though (Alt+Enter while standing on error and continue from there -- should work).

I mean -- setting "web" folder as resource folder does the job .. but not for URLs starting with extra prefix (like "/myproject/" in this case).

The proper way would be to access such image (resources) via different URL, for example: "" (where domain name is fakened via "hosts" file (available in any desktop/server OS) or local DNS server) and configure your web server to accept such requests. Alternatively -- use relative URLs (relative to the current file/URL) -- this way project will be self-contained and can be placed anywhere without any need to alter any URLs (unless URL rewriting is in use; it depends).

Other than that the only thing comes into my mind .. is to use PHP (or another technology, maybe LESS/SASS) to dynamically generate your CSS, e.g. something like this

<?php $urlPrefix = '/myproject';

a { background: url(<?= $urlPrefix ?>/images/image.png) }


Thanks for quick answer. I just wondered, could IDE help me.

I think I'll use SASS.



Please sign in to leave a comment.