CSS problem (background/background-image)

sadstoryitis

Registered
i ve never used the function "background" to create an background image until now- im trying to make this work but the problem is: if the code is in the page itself and not linked to the external css page it will work--->

Code:
<style type="text/css">
body{
       background: url(graphics/bg.gif);
       }
</style>

but when i move the code to the external css file it wont work (trust me, i ve tried changing the link function again n again to make sure the code s right)

Code:
body{
       background: url(graphics/bg.gif);
       }

this code wont work at all, even with the link tag in the index page. so what should i do?
 
Is your link tag for the external file good? It should be working...post a copy of what you're using.
 
sadstoryitis said:
this s what im using

<link rel="stylesheet" type="text/css" href="css/layout.css">

thanks.


Figured out your problem...look at your links carefully and you'll see the CSS is located in *****/css/ directory, while your images are located in *****/graphics/ directory. So when using the external CSS file your browser is looking for the image in *****/css/graphics/.

Try the following:

Code:
<style type="text/css">
body {
       background: #fff url("../graphics/bg.gif");
       }
</style>

You should also add the background color you want (replace #fff with whatever it is) to ensure some browsers don't make it grey or some odd color. Not all default to the same.
 
EDIT: Aah, MDNKY has posted the solution while I was writing this. Still, the validator is a good tool for future ref :D

Does another style sheet somewhere also set a background for BODY? something might be overridding it when you place it in the style sheet.

Could also be a wrong end brace {} in your style sheet that is stopping the styles below it from functioning. Try placing the BODY code at the very top of your style sheet( It's a long shot I know... :) )

Also, try validating your style sheet with the W3C validator to fine any errors that may be causing problems.
 
Back
Top