Cannot resolve directory in CSS files

Здравствуйте.

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

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



Attachment(s):
css_highlight.png
0
5 comments

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.

1
Avatar
Denis Nekhoroshev

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

0

Hi! I have the similar issue.

My project is one of the projects on the site. So url to image looks like:
http://localhost/myproject/images/image.png

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

My project structure is looks like that:
myproject
+bin
+src
+web
++images
++css

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

0

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: "http://myproject.dev/images/image.png" (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) }

0

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

I think I'll use SASS.

Thanks

0

Please sign in to leave a comment.