In case you don't know, xhtml is the same as html, just more strict. As a result of it being more strict, it's easier to make websites that look the same in all major browsers.
Ok, so let's get started. We are going to design our page with a header, two columns, and a footer.
If you want to follow along with this tutorial and make the pages (which I recommend you do... you'll remember it better), go ahead and create a new folder named my xhtml website or what ever. Create two files in it; index.html and style.css.
Now, for something very important. Your HTML is not for designing you website's look. That is what CSS is for... HTML is for the content, and CSS is for styling that content.
That is the whole idea behind CSS. Your website becomes a lot easier to manage and create when you separate your content from your styling.
So lets start with your html, Your content, then we will make it all look good.
Edit you index.html file to look like this:
Note that first line. That is where we tell the browser that the page is in XHTML 1.0. Also, in the <style> tag, the @import is to load our css file.
Now lets put our content in. Place this into the body (in the <body> tags):
That's our content... and all we have to do now on the html side. Yup, all done with sticky html! Kinda easy? heh, I think so :)
Before we go on to CSS, I want you to look at our content we have; how it's structured.
Our content is divided up into 4 sections. The header, sidebar, body, and footer. The sections are defined with the <div> tags, each div having an id to specify the name of that section.
One more thing I want you to note... the navigation. We are making it in the sidebar section with a list (the <ul> tag). A lot of developers often use tables to accomplish the task of creating a navigation. But with lists, we can be a lot more flexible.
Now, save your index.html page and see how it looks in a browser. Pretty plain. But that is exactly how it should show; no styling at all. If you think that something can't be done with CSS and you absolutely need to use HTML to style your website - think again - cause you're wrong :)
Now for the fun part: CSS!
Let's start with the header. Put this into your style.css file:
Now load your page again. Cool! The header has some styling to it! Awesome!
Ok, let's look at what we just did with the css. I hope you can see how most of it works... I'll explain.
In the first line, we see #header. The '#' means that the word after it is going to be an id of an html element. So in our case, your browser will look for the html element with an id of header. If we were to put a '.' instead, then it would look for all the html elements that had a class named header.
What is the difference between an id and a class? There is just one. You can use a class on as many html elements as you want... and an id you can use on only one element in your page.
Now below the first line is where we put all of our styling that is to be applied to the html element (in this case, a <div>) with the id of header.
I think the style properties we are applying are pretty self explanatory. I suggest you play with modifying the properties to see what happens (like change the border option to be border:3px dashed blue; or change the font-size to 80%).
Let's continue. Now we will style the sidebar and body, as they will go next to each other. So put this below the styling for your header:
Now reload your page. Wow! Looking better!
Soooo... what how did we do that?
Well, to keep this tutorial short, and because this isn't meant to be a reference for css properties, I'll give a very basic explanation.
In the sidebar, we have float:left;. That makes it so that the side bar floats to the left of the body element and not go to the default position above it. If you're not sure what I mean, try removing it from the css and see what happens.
For the body, we set a left margin of 300px. This is to put the edge of the body right up next to the sidebar (note that we set the width of sidebar to 300px). If we did not do this, the text of the body would rap around the sidebar (remove the left margin to see what I mean).
Ok, cool! Almost done. Now we got to get the footer to go where we want it to. Footers are a tricky thing with CSS. Put this in your style.css:
The clear:both; is our secret ingredient. It makes it so that it gets positioned (in our case) below all of the other divs on the same level as it!
Now, with the content we have, you won't notice a difference with or without the clear property. But make the sidebar longer than the body and you will be able to see what happens.
And finally, we will make the navigation look good. Our options are unlimited. In this tutorial, I cover some of the possibilities, but since this tutorial is mainly about the layout, I'll keep it simple this time.
So lets take off those bullets from our links! Add this to your css file:
Something new! After the #sidebar we have a ul! That simply means to apply the following style to all <ul> elements in the #sidebar element.
Simple? :)
Well, that's all for this tutorial! I hope you learned a lot! In case you didn't follow along, you can see the finial result here.
Oh, and as an exercise, try flipping around the two columns so that the body is on the left and the sidebar is on the right. Tip: you don't need to change any html to do this, only css!
Then once you are ready, In this tutorial I will talk about styling your navigation.
Have fun!
Joey
