Every time you start up a site, you generally use the same (or similar) process. Create your index, create and link this stylesheet, and that javascript.. I decided to make it a bit easier on myself and create a template. Not everything in the template will be needed for every site, but it’s a lot easier to delete a line or two than type out 800 characters.
I’ve created two templates. One for if you are simply working with (X)HTML, and the other if you are using PHP. I’ve separated the two because I believe that if you are using PHP (in a simple fashion) there are many structural things that make updating your site so much easier (i.e. making sections that stay the same throughout the site an “include”).
These ZIPs include a small file structure. I will do my best to go through and explain everything.
index.html/index.php
The index is where all of the files are linked together. This should be your base template for every page. I tend to rename it “template”, leave it in the site root, and then duplicate it every time I need a new page.
It uses a strict (X)HTML doctype, imports the Google hosted jQuery library and a local javascript file, links up the CSS, has conditional statements for Internet Explorer versions 6 and 7, as well starts off with a very robust document structure.
Javascript
jQuery
I use the jQuery library in almost every project I do. Even if I’m not going to use jQuery from the start, with a minimized file size of 4k, it’s easy to add some Javascript to a site if it’s already loaded. I also decided to stop copying the jQuery lib file into every project I do, but link to the file hosted by Google Code. There are many reasons why to, and not to do this, but ultimately it came down to one thing: it’s easy. The pros and cons can keep battling each other all day, but they really are going to even out.
global.js
Because I use the jQuery library so often, I added this global Javascript file. I tend to use JS for things like navigation drop-down animations, and other things that are globally located around the site. So, it only made sense to have a global Javascript file.
CSS
screen.css
The core of my skillset is mostly in CSS. With that, I don’t know what I would do if we still had to write inline styles (probably pursue my life long dream of Wife Carrying). The reason the file is named “screen.css” is because it simplifies the naming convention I generally use. Some times (and this is only when I’m SUPER bored) I do create a handheld and print stylesheet. In this file (screen.css) it imports another CSS file, reset.css
reset.css
Courtesy of Eric Meyers, this reset stylesheet removes most, if not all, browser default stylings. It places everything on the same level as to not run into any weird kinks later down the road that seem confusing. I can’t tell you how many times I’ve wondered “Why is that two points larger than it should?!”
Conditional Statements
Conditional statements, conditional statements, conditional statements… what are we to do? The very fact that Microsoft created an “out” just for them someone irritates me. These little buggers let you hide tags from any other browser that isn’t in it’s “condition”. If you don’t know what I’m talking about then have a look at Microsoft’s Developer Network.
Document Structure
I’m pretty sure I’m not the only one to have this document structure, but I don’t recall copying it elsewhere. After looking at as many lines of code as I have, things start to become a bit hazy. Either way, let me explain the best way to use this structure.
#wrap
I generally use the #wrap for some sort of background image applique. It works best when you have a repeating background image on the body, but need some sort of “topper” (if that makes any sense..). It’s just a div that fills the entire horizontal space, and as much space as your content takes up vertically.
.container
I used to use the #wrap to horizontally center my content. I did this until I met .container. What .container allows you to do is have a section (i.e. #branding) that spans the entire width of the document, but “contains” the content into a fixed (or even fluid) width that is smaller than the document. Example: your design has a black stripe behind the branding that goes all the way across the document, left to right. But the content only spans about 600px. You set the global .container width to 600px, and you can center it using some margin techniques. Bam! As well, if the content width ranges from section to section, just use the “cascade”, and call on the .container by it’s parent div id (i.e. #branding .container).
Sections (#branding, #content, #site_info)
Although I’ve been using CSS for quite some time, it was brought to my attention not to long ago how far we should take semantic coding. I’ve realized that id’s like #header and #right_col don’t have much value if you are restyling a document with no sidebar, or the “header” is now at the bottom of the page.. These sections that I’ve put in the document are not the “be all” of structure. In fact, in many of my projects they don’t work at all. But keep in mind when you are coding a document, “What content is going to be within this block of code?” and name it accordingly. BTW, if you are unsure of what #site_info is for, I generally put copyright, “footer” type things there.
I hope this can benefit somebody, as it has helped streamline my process by a lot. Thanks!