CSS background image on laravel 5.4 with {{ asset('path/image.png') }}
15,743
background images are relative to the css file. Ordinarily you would just specify the path like
.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
public/
img/
background-header.jpg
Related videos on Youtube
Author by
Bariq Dharmawan
60% web developer, 30% football, 10% unexpected things
Updated on June 04, 2022Comments
-
Bariq Dharmawan almost 2 years
Can I write css for background-image like this on laravel project?
.some-class { background-image: url('{{ asset('path/image.png') }}'); }
-
thefallen about 6 yearsYou can write this inline in the view.
-
Bariq Dharmawan about 6 yearsOk, thank for your suggestion
-
-
Bariq Dharmawan about 6 yearsso, the slash on before img it mean access photo from root, to the path of image?
-
Poornima Subramani Naidu almost 6 yearsExactly , / means the root of the current drive; ./ means the current directory; ../ means the parent of the current directory.
-
Synapsido almost 3 yearsConsole error shows GET localhost:8000/css/img/background-header, note the "css" folder, the correct solution is move up one level like this: url("../img/background-header.jpg");