I am having problems linking my css file. When I use the following the CSS works:
<link rel="stylesheet" type="text/css" href="./css/styles.css">
but when I use:
<link rel="stylesheet" type="text/css" href="/css/styles.css">
it doesn't work. I am using php includes to extract out reusable code. Like the banner, navigation and footer into separate files. The linking of the css code is found in the banner include file. Here is my problem how do I link the css file in such a way that each web page is able to find it. Do I use absolute path because I have web pages in separate folders. Any help is appreciated.
Thanks
Linking CSS
Moderator: General Moderators
- Peter Anselmo
- Forum Commoner
- Posts: 58
- Joined: Wed Feb 27, 2008 7:22 pm
Re: Linking CSS
If you have pages in different levels of folders (ie, some pages in the top-level folder and others in lower-level folders) you will need to use an absolute path. No relative path will work for both levels.
However, if all your pages are at the same level, but different folders, then you can use a relative path. Try making your link url start with "../" if it is up a level, or drop the leading slash completely to look in the current folder.
However, if all your pages are at the same level, but different folders, then you can use a relative path. Try making your link url start with "../" if it is up a level, or drop the leading slash completely to look in the current folder.
Re: Linking CSS
Thanks for the response. This is a newbie question but how do I use absolute paths? When I do this:
<link rel="stylesheet" type="text/css" href="http://localhost/bs/css/styles.css">
it does not link.
<link rel="stylesheet" type="text/css" href="http://localhost/bs/css/styles.css">
it does not link.
- Peter Anselmo
- Forum Commoner
- Posts: 58
- Joined: Wed Feb 27, 2008 7:22 pm
Re: Linking CSS
Hmmm. The structure of your link seems correct, assuming there are no typos. Of course - the "localhost" address will only work when previewing on your computer. When viewing online, you would have to use the actual website address.
Have you tried entering the address directly into the URL bar? Any absolute address should pull up the actual CSS file when entered.
Have you tried entering the address directly into the URL bar? Any absolute address should pull up the actual CSS file when entered.