0

ok, so i've been following this tutorial on how to add a simple web-responsive background image to a site. now, whatever I try to do, the background image won't show in the browser. This has happened to me before on a simmilar project, the background image wouldn't show, but i fixed that problem by using in line css. This time it didn't work. Strange thing is, I tried to copy-paste the code provided at the end of the tutorial, I copy-pasted the whole thing in separate HTML and CSS files and the funny thing is that the final web page result is showing but the image is not. Please help...

edit1:The project structure is failry simple, the HTML, CSS and .jpeg files are all in one folder.

edit2: SOLVED! Missing quotes in the background-image:url("poza.jpg")

the HTML is:

...
  <body>
    <h1>The biggest startup event of the year!</h1>
    <button>find out more!</button>
  </body> 

and the CSS for that is:

body,
html {
  background-image: url(poza.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  height: 100%;
  width: 100%;
  font-family: 'Montserrat', sans-serif;
 }```
mo_tan
  • 1
  • 1
  • show your project structure where image is located – vinod Oct 18 '20 at 18:09
  • it is a simple project structure of one folder with the HTML, CSS and jpeg file. – mo_tan Oct 18 '20 at 18:13
  • Your `poza.jpg` file needs to be available at the same endpoint, as the site using this code. For example, if you're accessing your site with `/index.html`, then this file needs to be at `/poza.jpg`. – Maks Babarowski Oct 18 '20 at 18:17
  • Hi mo_tan. open the inspector and see is the image is getting loaded so you can know the source of the problem – Moaz Mabrok Oct 18 '20 at 18:31

3 Answers3

1

Solution 1:You could try hard refreshing your browser using ctrl + f5 or try renaming image and try using another one Solution 2: Try to add slash and quotes before image like this url("/poza.jpg")

0

You should have quotes around poza.jpg

background-image: url(“poza.jpg”) no-repeat

And use the web browsers console to check if there is an error loading the poza.jpg file

Tom Harvey
  • 3,681
  • 3
  • 19
  • 28
0

use this ,

body {
  background-image: url(poza.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  height: 100%;
  width: 100%;
  font-family: 'Montserrat', sans-serif;
}

This should work.

Dtheekshana
  • 82
  • 1
  • 10