3 Replies - 651 Views - Last Post: 23 July 2011 - 02:27 PM

#1 teahou  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 223
  • Joined: 01-April 11

background-image not showing

Posted 23 July 2011 - 01:26 PM

Hi there. i have never had an issue with using background images, until today. Here is the code from the style.css file:

body {
	margin: 0px;
	padding: 0px;
	background-image: url('images/bg.png');
	background-repeat: repeat;
}



If I put the style directly in the body tag, it works, but when called from the .css file it does not. I know the .css file is linked to the html file corectly, because all the other styling is present. Only thing not working is the image. Ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: background-image not showing

#2 JizzaDaMan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 139
  • Joined: 23-May 11

Re: background-image not showing

Posted 23 July 2011 - 01:35 PM

You could try putting in the full file path of the image
Was This Post Helpful? 0
  • +
  • -

#3 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: background-image not showing

Posted 23 July 2011 - 01:54 PM

I guess you have the following file layout:

index.htm
styles/
    style.css
images/
    bg.png


Let's assume that index.htm is including styles/style.css as the stylesheet, and that is where the snippet above came from.

So here's the problem, when you put an image path into your CSS, it's not relative to the document that it's included on, it's relative to the stylesheet itself, thus you're attempting to access styles/images/bg.png based on the code above.

The way to fix this would be to either use a relative path that is correct, ie. come out of the styles/ directory with something like this: url('../images/bg.png')

Orrr you can use an absolute path, like this: url('/images/bg.png');

Both will work, so long as your site is in the root and not the subfolder, and if this is the case, it's normally better to use an absolute path.
Was This Post Helpful? 1
  • +
  • -

#4 teahou  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 223
  • Joined: 01-April 11

Re: background-image not showing

Posted 23 July 2011 - 02:27 PM

Thanks Rudi, that was exactly it. i didn't even think of that, so thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1