awebster Posted August 18, 2012 Share Posted August 18, 2012 I am trying to code my site and then I made my background image in gimp and then put it on my server but when I try body { background: url(img/background.png); } The background image doesn't show up and just white displays. I tried putting in the root of my server and that still didn't work. I validated to make sure of a syntax error and I had valid CSS code. Quote Link to comment https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/ Share on other sites More sharing options...
Mahngiel Posted August 18, 2012 Share Posted August 18, 2012 what is your file structure? where is the .css file located? so many questions, so little information Quote Link to comment https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/#findComment-1370498 Share on other sites More sharing options...
awebster Posted August 18, 2012 Author Share Posted August 18, 2012 My CSS file is located in a CSS directory on my server. All my other css code works. The only thing that didn't is the Background Image. Quote Link to comment https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/#findComment-1370499 Share on other sites More sharing options...
Mahngiel Posted August 18, 2012 Share Posted August 18, 2012 where is this 'img' directory in relation to the CSS dir? Quote Link to comment https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/#findComment-1370501 Share on other sites More sharing options...
awebster Posted August 18, 2012 Author Share Posted August 18, 2012 I have attached a picture of the directory set up. Quote Link to comment https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/#findComment-1370502 Share on other sites More sharing options...
Mahngiel Posted August 18, 2012 Share Posted August 18, 2012 your image folder is outside your css folder. therefore, the relative path to the image would be ../img/ NOT img Quote Link to comment https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/#findComment-1370512 Share on other sites More sharing options...
Pikachu2000 Posted August 18, 2012 Share Posted August 18, 2012 background: url(http://www.your_domain_name.com/full/path/to/file/img/background.png); Quote Link to comment https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/#findComment-1370517 Share on other sites More sharing options...
Christian F. Posted August 18, 2012 Share Posted August 18, 2012 URLs in CSS attributes are relative to the folder which the CSS file resides in. Since the CSS folder and the img folder are siblings, you need to go down one step to find it. Meaning the correct code would be: background: url('../img/background.png'); Quote Link to comment https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/#findComment-1370518 Share on other sites More sharing options...
White_Lily Posted August 26, 2012 Share Posted August 26, 2012 [/code] *class/id name* { background:url("*image directory*/*image file name(including extension)*") 0 0 no-repeat; } PS: if it needs to go back a directory in relation to the css file then add this at the beginning of the image directory: "../" = back 1 directory. "../../" = back 2 directories and so on. Quote Link to comment https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/#findComment-1372412 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.