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;
}
here is another image url result..working fine...i'm just put only a image path..please check it..
Fiddel:http://jsfiddle.net/287Kw/
I'd like to share my debugging process because I was stuck on this issue for at least an hour. Image could not be found when running local host. To add some context, I am styling within a rails app in the following directory:
I wanted to render background image in header tag. The following was my original implementation.
...as a result I was getting the following error in rails server and the console in Chrome dev tools, respectively:
I tried different variations of the url:
and it still did not work. At that point, I was very confused...I decided to move the image folder from the assets directory (which is the default) to within the stylesheets directory, and tried the following variations of the url:
I no longer got the console and rails server error. But the image still was not showing for some reason. After temporarily giving up, I found out the solution to this was to add a height property in order for the image to be shown...
Unfortunately, I am still not sure why the 3 initial url attempts with "../images/header.jpg" did not work on localhost, or when I should or shouldn't be adding a period at the beginning of the url.
It might have something to do with how the default link tag is setup in application.html.erb, or maybe it's a .scss vs .css thing. Or, maybe that's just how the background property with url() works (the image needs to be within same directory as the css file)? Anyhow, this is how I solved the issue with CSS background image not loading on localhost.
i can bring a little help here... it seems that when you use say background-image: url("/images/image.jpg"); or background-image: url("images/image.jpg"); or background-image: url("../images/image.jpg"); different browsers appear to see this differently. the first the browser seems to see this as domain.com/images/image.jpg.... the second the browser sees at domain.com/css/images/image.jpg.... and the final the browser sees as domain.com/PathToImageFile/image.jpg... hopes this helps
try this
I had the same problem when I used
background-image: url("yourimagefolder/yourimage.jpg");
Notice the slash that made the difference. The level of the folder was the reason why I could not load the image. I guess you also encountered the same issue
the following code worked for me where i had placed the image in somefolder/assets/img/background_some_img.jpg
I ran into the same problem. If you have your images within folders then try this
Don't forget to put the backslash in front of the first folder.