skip to Main Content

I am trying to add a background image for my website in Laravel 9.51.

I’ve used this in my css file:

body {
background-image: url("background.jpg");
}

But it doesn’t work. Also tried:

body {
background-image: url({{asset('background.jpg')}});
}

but it doesn’t work either. Any ideas? My background picture is stored in public folder.
Btw,
I can access it from my browser on route:
http://127.0.0.1:8000/background.jpg

4

Answers


  1. Chosen as BEST ANSWER

    Actually what worked for me was: background-image: url("/background.jpg"); (picture stored in public folder and I'm using Vite).


  2. Try with this one

    background: url("background.jpg") center center no-repeat;
    
    Login or Signup to reply.
  3. body {
    
        background:url('url-photo-background');
        background-position: center center;
        background-repeat: no-repeat;
        background-size: cover;
        height: 100vh;
        width: 100%;
    
    }
    
    Login or Signup to reply.
  4. You have to enter the photo with the address of the photo that is in the local

    body {
        background: url("/images/background.jpg");
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search