在 Laravel 中链接 CSS 图像 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42576329/
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
Linking a CSS image URL in laravel
提问by prgrm
I want to add a background-image with a laravel URL. I can do this by just including the web path itself but I would like to use Laravel URL.
我想添加一个带有 Laravel URL 的背景图像。我可以通过只包含网络路径本身来做到这一点,但我想使用 Laravel URL。
Here is how I do it now:
这是我现在的做法:
.mystyle{
background-image: url("www.myproject.com/assets/img/background.png")
}
Here is how I want it:
这是我想要的:
.mystyle{
background-image: url("{{ URL::asset('assets/img/background.png }}")
}
Any clues?
有什么线索吗?
采纳答案by Onix
You can even use it like this:
你甚至可以像这样使用它:
.mystyle{
background-image: url("/assets/img/background.png")
}
回答by Alexey Mezenin
回答by Kenzo
This absolutely work
这绝对有效
.mystyle {
background-image: url("../assets/img/background.png")
}
回答by Pratik Khadka
I have used inline css for a class and this is what actually worked in my case
我已经为一个类使用了内联 css,这就是我的案例中实际起作用的
style=" background-image: url('{{asset('images/cover.jpg')}}');"