图像未在 Laravel 4 框架中显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17127229/
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 07:58:20  来源:igfitidea点击:

Images not displaying in Laravel 4 Framework

laravellaravel-4

提问by user1072337

I am using the Laravel 4 Framework and I am trying to have some images appear on my page. I have two different cases. One, I am using an image as a background in a CSS file. The image is in a folder 'images', inside a folder 'assets', inside the public folder. The CSS of note is this:

我正在使用 Laravel 4 框架,并且试图在我的页面上显示一些图像。我有两种不同的情况。一,我在 CSS 文件中使用图像作为背景。该图像位于公共文件夹内的文件夹“图像”中的“资产”文件夹中。值得注意的 CSS 是这样的:

.banner-image{background:transparent url('/assets/images/hires_080820-F-5957S-987c.jpg') no-repeat center center;-webkit-background-size:cover;-moz-background-size:cover;background-size:cover; height:800px; min-width: 1200px;}

In the view, I call the CSS by using: <div class="banner-image"></div>

在视图中,我使用以下方法调用 CSS: <div class="banner-image"></div>

On the page, div is appear as white space (takes up the allotted pixels), but the image is not showing.

在页面上,div 显示为空白(占用分配的像素),但图像未显示。

In the same view, I am calling another image, using the html:

在同一个视图中,我使用 html 调用另一个图像:

<img src="/assets/images/fanssignupsplash.png">

However, the image is appearing as a broken link. Is there another style I have to use to call images in Laravel 4? Thank you for your help with these issues.

但是,该图像显示为断开的链接。在 Laravel 4 中我必须使用另一种风格来调用图像吗?感谢您对这些问题的帮助。

回答by Manuel

try in your View {{HTML::image('images/fanssignupsplash.png')}}

试试你的视图 {{HTML::image('images/fanssignupsplash.png')}}

回答by kJamesy

For the CSS, make sure the image is in a folder called assets, at the same level as the CSS file. And then try this:

对于 CSS,请确保图像位于名为assets的文件夹中,与 CSS 文件处于同一级别。然后试试这个:

.banner-image
{
  background: url('assets/images/hires_080820-F-5957S-987c.jpg');
}

In your View, try:

在您的视图中,尝试:

<img src="{{asset('assets/images/fanssignupsplash.png')}}">

Assuming you have the assets folder in your public directory.

假设您的公共目录中有资产文件夹。

回答by Stelian

Another way, in a view file

另一种方式,在视图文件中

<img src="{{ URL::asset('assets/images/fanssignupsplash.png')}}" />

fanssignupsplash.pngimage needs to be available at http://example.com/assets/images/fanssignupsplash.png

fansignupsplash.png图像需要在http://example.com/assets/images/fanssignupsplash.png