Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Why isn't my background showing up when I set it up through css?

td {background: url('initials.jpg')}

The file exists, I've checked the syntax 100 times, tried with firefox and IE, tried png and gif files, body instead of td, a nearly empty html with just html, header, css link, and body tags, and all of my hair is turning gray because my images are not showing but examples on w3schools.com work fine in their tryit example pages. What am I doing wrong here? Please!

Update:

I should also mention that all other statements and values produce results, even those within the background property such as color. I am only having a problem displaying background images, and only when I try it in a css file.

Update 2:

thanks for the idea, but I moved the image files to the same folder as the html and css files to rule that out, and I've checked the spelling and such over and over. I really don't get it. Could it ahve something to do with the fact that all this is on my pc as I'm building this rather than some web server?

Update 3:

ok, as for the src address and spelling and such, when I copy and paste all of that into the source file and alter it to become:

<body style="background:url('initials.png')"

it works just fine. isn't this exactly the same as putting

body{background:url('initials.png')}

into the css file?

3 Answers

Relevance
  • 1 decade ago

    If it works in the body tag but not in the CSS file, is the CSS file in a different directory to the normal HTML file? It's quite common to put it in a /styles directory, for example. Paths within the CSS file are then based on the location of the CSS file, not the HTML page using it.

    For example, if you have three files:

    www.example.xyz/index.html

    www.example.xyz/initials.png

    www.example.xyz/styles/website.css

    then your CSS file should do something like:

    body {background:url('../initials.png')}

    or

    body {background:url('/initials.png')}

  • ?
    Lv 4
    5 years ago

    Huuh? I thought CSS is a band?

  • Anonymous
    1 decade ago

    Check your URL path, although it is a correct syntax, but it doesn't necessary mean it can find it.

    For example, your initials.jpg could have been reside in images/initials.jpg

    so in your URL, you need to put "images/initials.jpg"

    Hope this helps

Still have questions? Get your answers by asking now.