Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking a CSS image URL in laravel

Tags:

css

laravel

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.

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?

like image 714
prgrm Avatar asked Mar 03 '17 10:03

prgrm


People also ask

What is URL () CSS?

The url() CSS function is used to include a file. The parameter is an absolute URL, a relative URL, a blob URL, or a data URL. The url() function can be passed as a parameter of another CSS functions, like the attr() function.


2 Answers

I have used inline css for a class and this is what actually worked in my case

  style=" background-image: url('{{asset('images/cover.jpg')}}');"
like image 115
Pratik Khadka Avatar answered Sep 23 '22 11:09

Pratik Khadka


You can even use it like this:

.mystyle{
    background-image: url("/assets/img/background.png") 
}
like image 40
Onix Avatar answered Sep 20 '22 11:09

Onix