I have followed all of the tutorials, which all say the say thing. I specify my background inside of body in my css style sheet, but the page just displays a blank white background. Image is in the same directory as the .html and the .css pages. The tutorial says that
<body background="image.jpeg">
is deprecated, so I use, in css,
body {background: url('image.jpeg');}
no success. Here is the entire css style sheet:
body
{
background-image: url('nickcage.jpg');
padding-left: 11em;
padding-right: 20em;
font-family:
Georgia, "Times New Roman",
Times, serif;
color: red;
}
for me following line is working for me , I put it in the css of my body ( where image is in same folder in which my css and .html files ) :
Other thing that you must care about is , be careful about image extension , be sure that your image has .jpeg or .jpg extension. Thanks
The path to the image should be relative, that means if css file is in css folder than you should start path with ../ such as
this is because you have to get back to home dir by ../ path and then /images/logo.jpg path to the image file. If you are including css file in html itself
I had the same issue. The problem ended up being the path to the image file. Make sure the image path is relative to the location of the CSS file instead of the HTML.
I had changed the document root for my wamp-server-installed apache web server. so using the relative url i.e. (images/img.png) didn't work. I had to use the absolute url in order for it to work i.e.
background-image:url("http://localhost/project_x/images/img.png");
If you place image and css folder inside a parent directory suppose assets then the following code works perfectly. Either double quote or without a double quote both work fine.
In other cases like if you call a class and try to put a background image in a particular location then you must mention height and width as well.
First of all, wave bye-bye to those quotes:
Next, if your html, css and image are all in the same directory then removing the quotes should fix it. If, however, your css or image are in subdirectories of where your html lives, you'll want to make sure you correctly path to the image:
Hope it helps.