|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
CSS Background
Greetings everyone!
I am having some problems with a CSS file. I have my template.htm where I call an external CSS file Code:
<link rel="stylesheet" type="text/css" href="CSS/style.css" /> I am just starting a new webpage and all that the style.css file consists of is Code:
<style type="text/css">
<!--
body {
background-image: url("Graphics/Layout/BG.png");
}
-->
</style>
For some reason though it will not set the background image that I am calling. I am missing some simple I'm sure but I cannot figure it out. I have tried getting it to work by putting the BG.png file and the style.css file into the same directory as template.htm, but that did not solve anything. My root folder holds my tamplate.htm file and then the folders 'CSS' and 'Graphics'. 'CSS' holds the style.css file and then 'Graphics' has another folder inside it 'Layout' which contains the BG.png image. Any help would be most appreciated. Thanks! Edit: Forgot to add that if I use the CSS code inside my template.htm file, it works great. I just cannot get it to work from an external CSS file. |
|
#2
|
|||
|
|||
|
RE: CSS Background
The stylesheet contains only informations about formating. No html tags.
In your case only these 3 lines. Code:
body {
background-image: url("Graphics/Layout/BG.png");
}
|
|
#3
|
|||
|
|||
|
RE: RE: CSS Background
Ok, I removed the HTML tags, but it still doesn't work. Or did I misunderstand what you said?
I doubt this has anything to do with it, but I just noticed that there is an "-" displaying on the page when I preview it to see if the background works. It is there even though there is nothing between the <body> tags. I will keep messing with this here trying to figure it out. Edit: NVM. I figured that part out. The "-" was hiding right after my <html xmlns="http://www.w3.org/1999/xhtml"> code at the top of the page. Thanks for the response. |
|
#4
|
||||
|
||||
|
RE: CSS Background
A quick hint: It's a good idea to use only lower case letters in directory and file names. This reduces frustration with remembering where the capital letters are.
Which makes me ask this question: Are you sure your css file is styles.css and not Styles.css for example? Or that it is in Graphics/Layout and not Graphics/layout for instance? You said you removed the HTML tags, did you also remove the HTML comments? Can you post both your HTML and CSS file here? |
|
#5
|
|||
|
|||
|
RE: RE: CSS Background
I doubled checked all possibilities for capitalization issues. Everything checked out. I went ahead and made everything lower case to prevent issues in the future.
Here are the contents of both files: template.htm Code:
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>TITLE REMOVED</title> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <META name="author" content="NAME REMOVED" /> <META name="geo.position" content="40.76;-86.36"> <META name="geo.region" content="US-IN"> <META name="geo.placename" content="Logansport"> <META name="dc.title" content="NAME/TITLE REMOVED" /> <META name="dc.language" content="en" /> <META name="copyright" content="© 2000-2005 NAME REMOVED" /> <link rel="shortcut icon" href="graphics/favicon/favicon.ico" /> <link rel="stylesheet" type="text/css" href="CSS/style.css" /> </head> <body> </body> </html> style.css Code:
body {
background: url("graphics/layout/BG.png");
}
The interesting thing is I've never had problems linking to an external CSS file before. I have compared previous sites I've done and everything related to CSS is done exactly the same. |
|
#6
|
||||
|
||||
|
RE: CSS Background
Okay, I think I know what the problem is.
Your directory structure is something like this - (main directory) - * template.html - * CSS/ - * - style.css - * graphics/ - * - layout/ - * - * bg.png If you put your css in the html file, it will get the bg from (main)/graphics/layout/BG.png, but when you put it in the CSS file, the browser will try to get it from (main)/CSS/graphics/layout/BG.png. So try changing the url to ../graphics/layout/BG.png or /graphics/layout/BG.png |
|
#7
|
|||
|
|||
|
RE: RE: CSS Background
Ok, I changed my CSS file to reflect the URL change
Code:
body {
background: url("../graphics/layout/BG.png");
}
It worked. I can't figure out why that would work and what I tried earlier wouldn't...I had a feeling that it had something to do with the file structure, so I took template.htm and style.css and put them into the same directory. I then edited both to reflect that. Then I moved BG.png into the same directory as those two and changed my CSS file to poing to just BG.png. None of that worked. However, thinking about it more, I still had HTML tags in the css file at that point. That is probably what messed it up. I knew it was something easy... Thanks again! |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > CSS Background |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|