Creating a CSS layout from scratch
7. Additional Structure
Now that we have the base layout divs in place, we can add the rest of the structure that will make up the bare bones of this website.
The main things we still need to add are:
- Navigation Links
- Headings (Site Headings and Content Headings)
- Content
- Footer Information (copyright info, credits, and alternative navigation)
In order to start implementing these things without breaking the page layout, we will create a helpful little class called “hidden”.
Add this near the top of your stylesheet, after the body tag definition:
.hidden {
display: none;
}
What this means is now we can set any element in the site to have the class “hidden”, and it won’t show on the page at all. This will come in handy later. You can forget about it for now.
Lets talk about headings.
Headings in an HTML document are defined by the tags <h1> through to <h6> in order of importance to the document. For example, <h1> for the website name, <h2> for the primary headings (ie page name), <h3> for secondary headings, etc…
We’ll add an <h1> inside our Header div, and set it to the name of the company, Enlighten Designs in this case.
<div id="header">
<h1>Enlighten Designs</h1>
</div>
If you refresh your page you will notice that Enlighten Designs has come up in big letters inside the header, but there is also now a lot of white space around the heading. This is caused by the default margins on <h1> tags. So we need to strip the margins and padding by doing this:
h1 {
margin: 0;
padding: 0;
}
Now we’ll add the navigation. The ins and outs of how the navigation will work can be rather complicated, and will be addressed fully in its own section later on.
The navigation will be structured as a definition list (<dl>) with individual id’s relevant to each navigation item on each definition term (<dt>). These Definition terms will have links to our major sections inside them. If that sounds confusing, just add this code to your main-nav div:
<div id="main-nav">
<dl>
<dt id="about"><a href="#">About</a></dt>
<dt id="services"><a href="#">Services</a></dt>
<dt id="portfolio"><a href="#">Portfolio</a></dt>
<dt id="contact"><a href="#">Contact Us</a></dt>
</dl>
</div>
In easy to understand terms, the <dl> acts as a container, the <dt>‘s are unique identifiers for each navigation item, and the links are…links.
We use the unique id’s later when we come to make this navigation look like it should, with its sexy image rollovers. But more on that later.
If you refresh, you’ll notice it looks a bit ugly, so for now, we’ll just hide the navigation we added, with the “hidden” class we made earlier.
<div id="main-nav">
<dl class="hidden">
<dt id="about"><a href="#">About</a></dt>
<dt id="services"><a href="#">Services</a></dt>
<dt id="portfolio"><a href="#">Portfolio</a></dt>
<dt id="contact"><a href="#">Contact Us</a></dt>
</dl>
</div>
“And like *that*, it was gone…”
Now we’ll jump down to the footer ‘cause its relitively easy. There are 2 parts to the footer, the copyright info and credits on the left, and the alternative site nav on the right.
We want the alternate navigation to float right, like we did with the sidebar and the content, so we’ll put that in the div first. In theory you should be able to float divs regardless of where they are in the source, but bugs in IE make this difficult, so for now, any floated items should come first in the source order.
Place it in a div with a unique id like so:
<div id="footer">
<div id="altnav">
<a href="#">About</a> -
<a href="#">Services</a> -
<a href="#">Portfolio</a> -
<a href="#">Contact Us</a> -
<a href="#">Terms of Trade</a>
</div>
</div>
Underneath that div, we will add the copyright and credits text.
<div id="footer">
<div id="altnav">
<a href="#">About</a> -
<a href="#">Services</a> -
<a href="#">Portfolio</a> -
<a href="#">Contact Us</a> -
<a href="#">Terms of Trade</a>
</div>
Copyright © Enlighten Designs
Powered by <a href="http://www.enlightenhosting.com/">Enlighten Hosting</a> and
<a href="http://www.vadmin.co.nz/">Vadmin 3.0 CMS</a>
</div>
And thats the footer done for now. Just to make sure you’re doing fine, this is what your site should look like:

Moving onto the main content area, lets add the content. I’m ripping this content directly off the design in step 2. Use <h2> tags for the headings “About” and “Contact Us”. Enclose the paragraphs in <p></p> tags, and use <br /> for line breaks.
<div id="content">
<h2>About</h2>
<p><strong>Enlighten Designs</strong> is an Internet solutions provider that specialises in front and back end development. To view some of the web sites we have created view our portfolio.</p>
<p>We are currently undergoing a 'face lift', so if you have any questions or would like more information about the services we provide please feel free to contact us.</p>
<h2>Contact Us</h2>
<p>Phone: (07) 853 6060<br />
Fax: (07) 853 6060<br />
Email: <a href="mailto:info@enlighten.co.nz">info@enlighten.co.nz</a><br />
P.O Box: 14159, Hamilton, New Zealand</p>
<p><a href="#">More contact information…</a></p>
</div>
Refresh your page you’ll notice there is more of that white space popping up around the content div. This is because of the default margins on the <h2> tags and the <p> tags.
We need to strip their margins and padding. However, we don’t want to do this to every single paragraph tag or secondary heading that’s going to be on the website. To do this we need to use ‘child’ CSS selectors.
All elements in HTML have a ‘parent, child’ relationship to one another. If ‘tag a’ is inside ‘tag b’, then tag b is the parent of tag a. In the code above, our <h2> tags and our <p> tags are both children of the #content div.
If we want to select the child elements of a specific parent, we separate them with a space, like the example below:
#content h2 {
margin: 0;
padding: 0;
}
#content p {
margin: 0;
padding: 0;
}
So the above rules tell the browser to apply these styles ONLY to <h2>‘s and <p>‘s that are child elements of the #content div.
Next we make the text look a bit better.
« Previous 1 2 3 4 5 6 7 8 9 10 11 12 Next »
70 Comments
-
Arizona Web Design says:Thanks so much for sharing all the information, I wasn’t hoping to find such complete tutorials for free. It may be an old article but the basic principles of website building and web design have remained the same.
-
Jason says:I just finished this tutorial, and although it was not current, it was very helpful. I have published my completed example (with a link to this page)at http://bit.ly/d9IEIb for anyone to check out. I will post links to the menu images and css file on my blog. Thank you for providing this resource. Can’t wait to see the update.
-
didik edhi says:It’s very usefull for me as newbie.good site..all the best.
-
Preston Racette says:Thanks so much for sharing all the information
-
Mike says:I have a question…I normally use tables to do my layouts, but now I’m using CSS but one thing I can’t quite figure out is how to use percentages correctly. With tables its quite easy, if you want the height the whole browser you use 100% and it’ll stretch whichever cell has a “*” in it. How would you accomplish this with css? I want to color the “sidebar” of this tutorial, but if you just add a background it only colors where the text is. I want it to span all the way from the bottom of the header image, to the footer. Does anyone have any information that could help me out or possibly a link to another article that covers this?
-
adam says:thanks a lot for this great tutorial..
easy to understanding ;) -
Harjit says:hey steve, this site tutorial is amazing, it actually proved to be very handy in understanding css and other functions of html. Though I’m getting stuck in one area, say if i create a button on the menus, how do i gett he onmouseover attribute to work? I have tried almost everything and for some reason I can’t get it to work? Can you help me…cheers.
-
Oliver says:Hiii Steve!
Great job! I know now why my “DIVs” didn’t work. You explain every parameter let us see the result and told us how to correct the bad things.
This way of doing things is more interesting than gave us a lot of code to copy/Paste wihtout a comprehension.Thanks a lot, I’m waiting for the new one.
-
Nick says:Thanks for this tutorial. I learned a lot, and it helped to clear up a lot of confusion about float based layouts. The only criticism I can give is that things got way too complicated at page 11. Everything up to that point was great, but the hacks and the advanced CSS just to do a menu, that stuff went over my head and I thought was not a good progression to the flow of the first 10 pages of your tutorial! Other than that, I found it very useful and look forward to visiting your site again.
-
php tutorial says:Nice article. Even if it is old, but it contains useful information.
-
Bashar says:Really looking forward to the updated version. It’s the best CSS layout tutorial I found honestly
-
Hassan Naqvi says:This article had been my doorway into the css world. Before this article I was designing websites the old-fashioned way using tables. This article is written in such a way that I still refer to it for inspiration and making my css simple.
Looking forward to the new one. Hope this one will still be available.
-
Medyum Hoca says:Really looking forward to the updated version. It’s the best CSS layout tutorial I found honestly
-
icon creation says:Many applications pack all their data files into a single file, using internal markers to discern the different types of information contained within. The data files used by games such as Doom and Quake
-
Arch-Area says:Without this article, my game would never exist :) Cheers!
-
sunny says:Thanx!! a lot Steve for such an easy and understandable tutorial. Specially the float & clear part is very clear and easy to understand.
Looking forward to see more such articles.
Thanx!! Buddy
-
sunny says:Hi!! Steve,
I have a problem, when I am publishing my file in Mozilla Firefox, margin: 0px, padding: 0px; for html, body selector is not supporting & it shows the default 8px margin from top. Main nav is also having some problem.
Please help….
Thanx!!
Sunny
-
web designer india says:wow good tutorial its very use full
-
stendmaster says:Если бы я все это знал до того, как слизал сайт по шаблону.
-
nzyme says:now this is something interesting.its an excellent tutorial !!! keep up the good work. I did mess up at some places, but it was really helpful :)
-
Chris says:Awesome tutorial. It’s the first one I actually understood in depth. I noticed that no position attributes were used. I always am getting confused by absolute vs. relative. Why would you use those if you can lay a page out like this? What are the benefits and differences between them? If anyone could answer this I would greatly appreciate it. Maybe even pointing me to another tutorial that is as clear as this one would be extremely helpful.
-
ENGLISH34Valerie says:Houses are quite expensive and not every person is able to buy it. Nevertheless, <a href=“http://bestfinance-blog.com/topics/mortgage-loans”>mortgage loans</a> was invented to help people in such kind of cases.
-
Pranav says:Hi Steve! Thanks for this awesome tutorial! I have been running websites (plain html/blogs/forums etc) since 2006 and have tried my luck at many CSS tutorials till now. This was the first time I was able to read and understand it fully… Thanks a lot!!
-
bee says:Great tutorial until I got up to page 11! For the life of me I can not get the navigation to work. Ive been throught it a million times but the navigation is not showing up. The click throughs work so I know its there but I cant see anything! Can anyone help?! It would be a shame to give up now when Im so close.
-
Bee says:Thanks Steve! I just overwrote some of my code with yours. Just a couple of things I noticed which is giving me a bit of headache.
Firstly the padding on the side bar doesnt seem to be working anymore?
#sidebar-a .padding {
padding: 25px;
}
I still cant get these clicked images to work. Please see below to see how I am doing it. I have done the ‘services’ class to show you what I did. (Just so you know, all my images are in one folder local to the css)body.about #header {
height: 150px;
background: #db6d16
url(images/about.jpg);
}
body.services #header {
height: 150px;
background: #db6d16
url(images/services.jpg);
}
Hope you can help! Thanks again. -
Praca says:Great tutorial I was looking for sth like this long time, thanks a lot.
-
Jason W says:This is by far the best CSS tutorial I have gone through. Thanks so much for this, I know this is an old article but it’s relevant and very useful even today.
-
iFranzi says:nice tut.
-
Nirupam Burman says:Hi Steve,
Awesome work by you,2 thums up.I always had/has/have problems using css with div..alignment and making sections etc..now i am bit confident..just if you could let us know a lot of generic hacking techniques to overcome browser problems it would be so useful because it adds up value to others experience.
Just like the way you have explained this tutorial it would be just great.
Eagerly,waiting for your reply. -
Nirupam Burman says:Its awesome tutorial..2 THUMS UP.i think i am more confident now with div/css..alignment and positioning was the problem i was facing..anyways,it would be really helpful if you could teach css hacks and some of the generic hacks and best practises.
And also css alignment of div ..to design any type of site.. -
LearnWebsiteDesign.com says:This is one of the tutorials that first helped me to understand how to create css layouts.
Thanks
Jose

Hey Steve - old article or not this is a nice & simple explanation of how ‘float’ works. I’ve always battled to get my head around those ... cheers!