Laravel 5.4 上的 CSS 背景图像,带有 {{ asset('path/image.png') }}

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

CSS background image on laravel 5.4 with {{ asset('path/image.png') }}

laravellaravel-5laravel-blade

提问by Bariq Dharmawan

Can I write css for background-image like this on laravel project?

我可以在 Laravel 项目中为这样的背景图像编写 css 吗?

.some-class {
  background-image: url('{{ asset('path/image.png') }}');
}

回答by Poornima Subramani Naidu

background images are relative to the css file. Ordinarily you would just specify the path like

背景图像是相对于 css 文件的。通常,您只需指定路径,例如

.some-class{
background-image: url("/img/background-header.jpg"); 
}

The above css code works if you are accessing images from public folder like for example

如果您从公共文件夹访问图像,则上述 css 代码有效,例如

public/
    img/
       background-header.jpg