php 在 Laravel 5 中添加背景图片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41323845/
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
add background image in laravel 5
提问by Harsh
I am trying to add a background image for my website in Laravel 5.
我正在尝试在 Laravel 5 中为我的网站添加背景图片。
I've used this in my css file.
我在我的 css 文件中使用了它。
html {
background-image: url("images/background.jpg");
}
the image is in the public folder of my Laravel project folder. I tried all the paths but it just doesn't load.
该图像位于我的 Laravel 项目文件夹的公共文件夹中。我尝试了所有路径,但它只是不加载。
I keep getting this error:
我不断收到此错误:
http://Laravelproject.app:8000/background.jpg 404 (Not Found)
Any help would be appreciated. Thanks.
任何帮助,将不胜感激。谢谢。
回答by Alexey Mezenin
Works just fine with slash:
用斜线工作得很好:
html {
background: url("/images/background.jpg");
}
回答by Ndong Akwo
Might be answering a little late but do this and hope it helps someone out there:
可能会晚一点回答,但这样做并希望它可以帮助那里的人:
background-image:url({{url('images/php_mysql.jpg')}})
回答by Ndong Akwo
You have to get out of CSS first by adding two dots. Here I am going to show you an example, which I just tested and works fine in Laravel 5.7
你必须先通过添加两个点来摆脱 CSS。在这里,我将向您展示一个示例,该示例我刚刚在 Laravel 5.7 中测试并运行良好
Make new class in your CSS and name it login body.
Your css code should look like this.
.loginbody { background-image: url("../images/bg.jpg"); }
Add this class to the body of the page where you want the image.
- Save and run.
在 CSS 中创建新类并将其命名为 login body。
您的 css 代码应如下所示。
.loginbody { background-image: url("../images/bg.jpg"); }
将此类添加到您想要图像的页面正文中。
- 保存并运行。
Note:be careful with your path, where the image exist. In my case the image is in "public/assets/images/bg.jpg"
注意:小心你的路径,图像存在的地方。在我的情况下,图像在“public/assets/images/bg.jpg”中
回答by Sara Vaseei
I use
我用
background-image: {{asset("/images/background.jpg")}};
and my image is in public/images
我的形象在 public/images
回答by D.Saidi
i use
我用
background-image: url({{ asset('images/job.jpg') }});
回答by Bruce Justice Selorm
This works
这有效
background-image: url({{asset('images/bg.jpg')}});
回答by Adnan Zaheer
i am still unable to access image via css in Laravel 6
我仍然无法通过 Laravel 6 中的 css 访问图像
but
但
this code is work for me
这段代码对我有用
(add image path in blade.php file)
(在blade.php文件中添加图片路径)
<div id="loading" style="background-image: url('{{ asset('img/big-loader.gif')}}');">
回答by bcg
since you're in css, you need to get out of it first using the two dots. url("../images/background.jpg");
因为你在 css 中,你需要先使用两个点来摆脱它。url("../images/background.jpg");
回答by AL FAISAL MIA
You can use this css of the specific class/id:
您可以使用特定类/ID 的此 css:
selector{
background-image: url({{URL('/')}}/public/assets/landing/images/paper.jpg);
}
{{URL('/')}}
means the base url of your project locations
{{URL('/')}}
表示您的项目位置的基本网址
回答by warrene valdez
Try this code snippet, this one works on me :
试试这个代码片段,这个对我有用:
url({{ URL::asset('images/SampleBackground.jpg')}})