A Path Less Taken

Breaking with convention in a very conventional fashion. Powered by WordPress

"What would you attempt to do if you knew you could not fail?"
Dr. Robert Schuller

Saturday, June 6, 2009

Category: Web Development Author: JJ 0 Comments

As a programmer I’m about making things easier. I create a main page, set it up to go and then start coding away in other files. That’s why EVERY TIME I start a new project of any size I spend a minute scratching my head and going “how do I include that CSS file again?” I figured if you are as bad as I am I would provide you with a brief tutorial so that BOTH of us won’t forget.

The first approach and the easiest to use is the HTML [link] tag. This tag is placed inside of the [head] tag. Below is an example of this.

1
2
3
<head>
   <link rel="STYLESHEET" type="text/css" href="/css/main.css" />
</head>

This works pretty well and is easy to implement. I did encounter one issue with the lighttpd web server in that it tries to resolve relative references in the href tag above from the document root. This was an issue because the file with the link tag was in a sub folder. nitrox on the lighttpd IRC channel (irc.freenode.net) helped me sort this out. I think that Apache and IIS will try to resolve the reference relative to the folder of the page requested.

The other approach is to use the @import rule from CSS2. This is a statement that is added inside a style tag and includes and external style sheet where it sits. I could try to explain this, but I would prefer to let others who are more capable and knowledgeable than me do it. Check out the link below for some good information on @import.

http://css-discuss.incutio.com/?page=ImportHack

I hope this post helps you (and me) avoid any issue in the future. If you have a question or would like to correct my description or word choice please post a comment.

Peace

No comments found. Please enter a comment if you have a question or contribution.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">