Jump to content

Problem linking to external CSS file


SteveHoffmanUK

Recommended Posts

New to HTML/CSS, very impressed by W3Schools tutorials and hoping to free myself from WYSIWYG authoring tool. But, am having a problem getting my external CSS to work. Using Firefox 2.0 in Linux (Ubuntu), if that's relevant.Have set up file parishmagstyle.css, which contains this code:

<html><head><style type="text/css">body {background-image:url('parishmagbackground.gif')}{background-color: yellow}</style></head><body></body></html>

This CSS file is located in the same directory as my html file, index.html, which contains this code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Whitchurch Parish Magazine</title><link rel="stylesheet" type="text/css" href="parishmagstyle.css" /></head><body></body></html>

The background image file parishmagbackground.gif is also in the same directory as the above two files.I have tried putting the background-image statement directly in the index.html file, and it works fine, so I know that the .gif image itself is OK. I have tried inserting a background-color statement in my parishmagstyle.css file and it doesn't take either. It seems clear to me that the link to my external stylesheet isn't working, but I cannot see why. It's probably something obvious, possibly to do with my file addressing, but this newbie has run out of ideas.Can someone tell me what I'm doing wrong?

Link to comment
Share on other sites

I found I had to put a / beforethe file path to get it to work in my website. But i'm sure someone more experienced will tell you something different.

Link to comment
Share on other sites

From the information you provide, I would think that this is all that you should have in the css file:

body {background-image:url('parishmagbackground.gif');background-color: yellow;}

The html, head, style and body tags are for the html file only, and don't belong in the css file.

Link to comment
Share on other sites

From the information you provide, I would think that this is all that you should have in the css file:
body {background-image:url('parishmagbackground.gif');background-color: yellow;}

The html, head, style and body tags are for the html file only, and don't belong in the css file.

jlhaslip: It worked - thanks very much. I knew it must be something pretty basic! :)
Link to comment
Share on other sites

And so the problem is solved before I could even see it :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...