laravel 在 phpstorm 中设置背景 css 图像 - “无法解析文件”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29805943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:25:25  来源:igfitidea点击:

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

htmlcsslaravelphpstorm

提问by Growler

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

我有一张图片,我想在 Laravel 3 项目中设置为背景 - background-image: url("public/img/find-a-table.png");

But it's saying "cannot resolve find-a-table.png" in phpStormeven though I definitely have the image file added to that directory.

但是它在phpStorm 中说“无法解析 find-a-table.png”,即使我确实将图像文件添加到该目录中。

Do I need to change something to have it find my image in that directory? In any other typical web app, this would be quite trivial to do so I don't know if I'm missing something.

我是否需要更改某些内容才能在该目录中找到我的图像?在任何其他典型的网络应用程序中,这将是非常简单的,所以我不知道我是否遗漏了什么。



this siteshows I don't need the quotes around the path? I've tried that too but that doesn't fix it. They use:

该站点显示我不需要路径周围的引号?我也试过了,但这并不能解决问题。他们使用:

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

background: url(images/bg.jpg) no-repeat center center fixed;没有引号

回答by Alexander Bondar

phpStorm does not tell you, that your browser will not see the given file. It just tells that phpStorm itself does not see the file.

phpStorm 不会告诉您,您的浏览器将看不到给定的文件。它只是告诉 phpStorm 本身没有看到该文件。

You have to tell phpStorm where the relative path(es) start(s).

您必须告诉 phpStorm 相对路径从哪里开始。

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

要做到这一点,打开您的项目文件结构(cmd + 1在Mac),右键点击你的(公众开放)根目录(public),然后Mark Directory as >Resource Root。几秒钟后,错误消息应该消失。

回答by Konstantin L

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

请记住,图像路径应该相对于您的 css,如果以 .css 开头则是绝对路径/

Try this background-image: url("/img/find-a-table.png");Or this background-image: url("../img/find-a-table.png");if your cssfolder is alongside img

试试这个background-image: url("/img/find-a-table.png");或者这个,background-image: url("../img/find-a-table.png");如果你的css文件夹在旁边img

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

public/的网址中可能不需要。并且不要依赖phpstorm,在浏览器中测试它。

回答by Jonca33

Here is the fix:

这是修复:

1- Right-click on your (public accessible root directory) where you're sourcing the images from.

1- 右键单击​​您从中获取图像的(公共可访问根目录)。

2- Scroll down to Mark Directory as

2-向下滚动到将目录标记为

3- Choose Resource Root

3-选择资源根

enter image description here

在此处输入图片说明

回答by ANshul Sharma

Had this same error in my WebStorm IDE which was resolved by adding "../" before the path. try this:

在我的 WebStorm IDE 中出现了同样的错误,通过在路径前添加“../”来解决。尝试这个:

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