Jump to content

Recommended Posts

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. 

Link to comment
https://forums.phpfreaks.com/topic/267284-background-image-css-code-not-working/
Share on other sites

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');

[/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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.