Basic CSS layout
Basic CSS layout
This tutorial guides you through how to make a website layout using nothing but CSS.
1. |
We will start with a header. For this we will set out a div tag and give it the id header. <div id="header"></div> Then in our CSS file we will place this code: #header { Basically sets the background to white and width to 760 pixels, which means it will fit on a maximised window on an 800x600 resolution. The clear property means nothing can be to the left or right of the header. |
2. |
Now we will add another div inside our header div and call it title. <div id="title">Site Name</div> So our complete HTML so far looks like this: <div id="header"> <div id="title">Site Name</div> </div> The CSS is as follows: #title { This removes all padding for the div as well as setting the background to white. #CC0000 is the hex for a dark red which will be our text colour. The font size here is 3em as I have defined the font-size to be usable for people that need different size text. I prefer to use either em or px in my sites. |
3. |
Now that is our header complete. I am now going to create a horizontal navigation bar. <div id="nav"> This is just a simple navigation bar, note that in text browsers with no CSS support this will display as: <a xhref="http://skeletorscorpse.com/joomla/#">Link</a> <a xhref="http://skeletorscorpse.com/joomla/#">Link</a> <a xhref="http://skeletorscorpse.com/joomla/#">Link</a> <a xhref="http://skeletorscorpse.com/joomla/#">Link</a> <a xhref="http://skeletorscorpse.com/joomla/#">Link</a> For the CSS, we will first define the actual nav div so that we can get the correct formatting for it. #nav { As with the header I have set clear to both so that the content won't be able to move itself next to it. The width is set the same as the header and i've added some padding and a small margin at the bottom of the navigation bar. |
4. |
Now we need to add the CSS for the actual links: #nav a { These are all pretty basic properties. Change the padding to what ever you want to change the size of each button. #nav a:hover { This just changes the background slightly on rollover. You can also add some CSS for visited and active links too if you wish. |
5. |
Now we have our header and navigation bar. Now for the content area. I am creating a 2 column layout so I am going to use a container for both of the smaller content areas. <div id="content"> </div> Inside this we will put the rest of our content area. #content { This CSS as with the header and nav simple sets the width and makes sure nothing appears to the left or right of it. I have also added a border at the top of the content area so its seperated from the nav bar. |
6. |
I am going to have a large column on the left with a smaller column on the right. For the left column I need to add another div tag. <div id="maincontent"> </div> For the CSS i just set out some simple formatting and added a border to the right so that it is visibly seperated from the 2nd column. #maincontent { |
7. |
For the right hand column we need to make it slightly smaller as well as changing the side its floating on: #sidecontent { And we will just create another div for our second column: <div id="sidecontent"> </div> |
8. |
I will now use the same sort of formatting for the footer, so create your div tag: <div id="footer"> </div> Then use this CSS: #footer { I am using this as another container. As I am going to split the footer in to a left and right side. |
9. |
So we now need to add our CSS for the 2 sections of the footer: #copyrightdesign { #footercontact { This is all pretty simple and uses the same formatting as the content area. |
10. |
We now have a full layout with header, navigation, content and footer. HTML: <div id="header"> <div id="title">Site Name</div> </div> <div id="nav"> <div id="content"> <div id="maincontent"> <h1>Content Header</h1> <p> <p> </div> <div id="sidecontent"> <h1>Latest News</h1> <p> <p> </div> </div> <div id="footer"> <div id="copyrightdesign"> <div id="footercontact"> </div> CSS: * { body { h1, h2, h3, h4, h5, h6, p, pre, blockquote, label, ul, ol, dl, h1 {font-size:1.67em;} h2 {font-size:1.39em;} h3 {font-size:1.2em;} h4 {font-size:1em;} li, dd { margin-left:5%; } fieldset { padding: .5em; } a { a:hover { #header { #title { #nav { #nav a { #nav a:hover { #content { #maincontent { #sidecontent { #footer { #footer a { #footer a:hover { #copyrightdesign { #footercontact { As you can see I have added some additional CSS for the formatting of the text etc. |