Last week, I taught you how to slice Six Revisions’ layout in 12 easy steps. Today I’ll show you how to code their layout better than them!

There are many blogs out there that I really like: Smashing Magazine, Freelance Switch, Think Vitamin, Designm.ag, Nettuts, etc. Six Revision is one of them. Unfortunately, sometimes their articles is not as good as they should be. (Not only for Six Revisions.)

I mean, they have the money, they have the fame… but they should give me money and fame and concentrate on writing content of the highest quality. Hence I decided to write a “better than” series to show how to take some of their articles from good to great. That’s my way to pay tribute to these blogs I love.

Before you begin

You can read how to design Six Revisions’ layout, and how to slice it. Or simply download the sliced pics we need in order to do this tutorial.

You can also read the article we are going make better: Minimal and Modern Layout: PSD to XHTML/CSS Conversion or already check the final result.

What is “better” for me?

It’s not about how the tutorial is well-written, or full of good-looking pictures. It’s about code quality, standard compliance, best practices, work-flow, and tricks you should use to work more efficiently.

Download My Simple Framework:

In order to work quicker and better, download My Simple Framework and unzip it. (If you want, take one or two minutes to get familiar with it.)

It should look like this inside:

msf main folder

Today we will code in XHTML, so open the XHTML folder. Here is what you should see:

XHTML

Why is it better?

It is better than Six Revisions’ tutorial for many reasons. In short, My Simple Framework (MSF), will take care of many issues that Six Revisions’ tutorial forgot or neglected. (Other frameworks such as 960.gs, Blueprint, etc. are good too.)

For example, MSF provides a powerful build in CSS reset and many useful default values, but Six Revisions use an old and “not so good” CSS reset:

* {
margin: 0px;
padding: 0px;
border: none;
}

Another example: Six Revisions wrote NOTHING about typography. But typography, it’s rhythm, it’s flow, the font choice, etc. are an important part of any design and should be taken in account when building a layout. MSF features a beautiful typography, with many size and baseline grids.

More: MSF provides a xml:lang attribute, an IE special stylesheet, a print stylesheet, etc. Six Revisions’ tutorial lacks all these.

Creating the layout

1. First let’s take a look at what we want to create. Here is the structure of our web template:

structure

You don’t need to code anything yet. A mere copy-paste will be enough to create a good basic layout. But (sadly) whereas the usual width for layouts is 960px, this one is 850px large… (what for? I wonder…)

2. Open “css/layout/960px fixed layouts/” and copy head-nav-2col(1-2)-2col(2)-960px.css

select css layout

3. Go back to the “css” folder and replace layout.css with this file (delete layout.css, paste head-nav-2col(1-2)-2col(2)-960px.css, rename it layout.css):

rename css layout

4. You can already take a look at your website and open index.php with your favorite web browser (I’m sure it’s Firefox!). Here is what you should have:

first screen

Not bad for a mere copy-paste, right? Now, we simply need to merge the header and the navigation section, and to give their width to our layout elements.

5. Open up index.php in your favorite code editor; I’ll be using Notepad++ for this tutorial (for bigger projects, I like Aptana Studio). Find the following code:

<div id="top-nav">
<div class="inside">
<!-- add your content here -->Nav
</div>
</div>

<div id="header">
<div class="inside">
<!-- add your content here -->Header
</div>
</div>

<div id="nav">
<div class="inside">
<!-- add your content here -->Nav
</div>
</div>

Delete the navigation sections so that only the header remains:

<div id="header">
<div class="inside">
<!-- add your content here -->Header
</div>
</div>

6. Now, open layout.css. In order to give the proper width to all your layouts elements (columns, header, wrappers, etc.), you can use the search and replace function (ctrl+f):

  • search for: 960px, replace with 890px;
  • search for: 240px, replace with 300px;
  • search for: 720px, replace with 620px;

Here is the result:

structure ok

Why is it better?

First of all, this layout can be done in seconds if you know what you want to do. I mean 1 copy-paste, delete 2 sections of text, and do 3 search and replace can be done in less than 50 seconds.

Then, a big flow of Six Revisions markup is that the content appears AFTER the sidebar. It’s not (really) good for SEO and accessibility. With my method, your content (level-2 > column-5) appears before the sidebar (level-2 > column-6).

One more crucial thing: It’s an organized workflow! You can’t slice a part, code some CSS, slice another thing again, write some XHTML, slice again, code again, and so on. That’s just wrong! If you don’t want to fail like an amateur, please use some kind of plan, for instance: Design / Slice / Layout (XHTML) / Layout (CSS) / Content (XHTML) / Content (CSS) / Features (jQuery) / etc.

(I only stress the important things because it would be too long if I wanted to write everything that is better).

Adding the background

7. Make sure that you have all the required sliced files. (You can also download the whole “layout” folder again).

Put all these pictures in “images/layout/” like this:

I love ferrets

8. In layout.css, delete the default backgrounds:

/* Default background - delete when not needed anymore */
body { background: #d5e8f3 url(../images/layout/body-bg.png) repeat-x top; }
#header, #top-nav, #nav, #level-1, #level-2, #footer { background: #fff; }
.inside { background: #f1f1f1; }

9. Then starting with the body. We are going to add all the backgrounds (please note that when required, we will add the proper height/margin/padding too):

body {
background: #001b32 url(../images/layout/top-bg.png) repeat-x top;
min-width: 890px;  /* Prevent the liquid layouts from breaking */
}

/* Section for additional styling purpose */
#main-wrapper {
background: url(../images/layout/main-highlight-bg.jpg) no-repeat center 120px;
}

10. For the column-2, we must add a 370px height to protect the background:

#column-2 {
background: url(../images/layout/right-pics.png) no-repeat -2px  top;
height: 370px;
float: left;
width: 49.99%;
}

11. Here, the 60px padding-top provides enough space to display the horizontal bar:

#wrapper-2{
background: url(../images/layout/middle-hr.png) no-repeat center top;
margin: 0 auto;
padding: 60px 0 0 275px;
width: 560px;
}

12. For the sidebar, we are going to layer to background images in order to use the sliding-door technique. Hence, we need to delete the margin of the inside div. Moreover our slice is not pixel-perfect so we are going to “move” our background a bit:

#column-6 {
background: url(../images/layout/sidebar-box-top.png) no-repeat 4px top;
float: left;
width: 275px;
margin-left: -100%;
left: 275px;
}

/* Protect the layout from IE strange behavior */
#level-2&gt;#column-6  {
left: -275px;
}

#column-6&gt;.inside {
background: url(../images/layout/sidebar-box-bottom.png) no-repeat 4px bottom;
margin: 0;
padding: 0 60px 40px 23px;
}

Why is it better?

With this method, the sidebar height can increase without breaking the layout. If you used Six Revisions’ layout and put too much content, very bad things would happen:
very bad sidebar

Oh! And I forgot another (small) better thing. A width of 890 pixels is better than 850 pixels for this layout because that allows consistent margins around the content. (And consistent things are sweet).

Adding Content

Up to now, our website is only an ugly creature with no meaning. It’s time to turn it in a talkative little princess: let’s add the content.

13. When you add the content, you should always keep in mind how you are going to style it later in your CSS file(s). You should also be careful and use the proper XHTML tags for each element you write.

14. That being said, we can edit our index.php file again. First we are going to add the site title and the navigation menu. Find the header section and write this:

<div id="header">
<div class="inside">
<h1><a  href="#">Your</a><a  href="#">Website</a></h1>
<h3><a  href="#">Your Jazzy Slogan Here</a></h3>

<ul>
<li id="home"><a href="#">Home</a></li>
<li id="about"><a href="#">About</a></li>
<li id="portfolio"><a href="#">Portfolio</a></li>
<li id="contact"><a href="#">Contact</a></li>

</ul>
</div>

</div>

And in layout, change #header>.inside to:

#header>.inside {
margin: 0 10px;
padding: 0 10px;
}

Why is it better?

Because we don’t use any image for the logo (I can’t see any good reason to use an image for a text with no gradient…). And we’ll be able to style the logo through CSS only later, with a small trick :)

Our solution is better too, that’s only a detail, because we didn’t specify a class for the unordered list. (You can target this list with CSS only, there is no need to add a class here. Moreover a “ID” would be more suited in this situation).

Last thing, adding a class to the last list item is just wrong. Please use the CSS selectorsdon’t add unsightly crap to the markup!

15. Now add the content and the sidebar markup:

<div id="column-1">
<div class="inside">
<h2>welcome to <span class="h-color2">yourwebsite!</span></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque lacinia pellentesque neque in hendrerit. Suspendisse in malesuada mi. Donec in dictum neque. Mauris vel lacus eget risus fermentum tristique. Nulla ac elit augue.</p>
<p>Proin fringilla nunc lorem, in sollicitudin orci. Sed ut eros ligula.</p>

<ul>
<li>Lorem ipsum dolor sit amet...</li>
<li>Lorem ipsum dolor sit amet...</li>
<li>Lorem ipsum dolor sit amet...</li>
<li>Lorem ipsum dolor sit amet...</li>
</ul>
</div>
</div>

And:

<div id="column-5">
<div class="inside">

<h2>welcome to <span class="h-color2">yourwebsite!<span></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque.</p>

</div>
</div><!-- end div #column-5 -->

<div id="column-6">
<div class="inside">

<h3>lorem ipsum dolor</h3>

<ul>
<li>Lorem ipsum dolor sit amet, consectetur sit adipiscding...</li>
<li>Lorem ipsum dolor sit amet, consectetur sit adipiscding...</li>
<li>Lorem ipsum dolor sit amet, consectetur sit adipiscding...</li>
</ul>

</div>
</div><!-- end div #column-6 -->

16. We can finish with the footer (I’m leaving Six Revisions’ copyright without adding mine because I’m a nice fellow):

<div id="footer">
<div class="inside">

<small>Copyright &copy; Six Revisions - Design By Richard Carpenter</small>

</div>
</div><!-- end div #footer -->

Why is it better?

Well… again we are using a little less markup (and, if you read the recommendations of W3C, that’s definitely a habit you have to take as soon as possible).

However, I must admit that generic column names such as “column-5″ are less semantic than “sidebar” and “content”. (But, sometimes you can’t make everything perfect.)

One other benefit of building your website like I’m showing you is that you (somehow) follow the rules of progressive enhancement. It means that you add layers of technology one by one and make sure that everything is as accessible as possible.

Here is what you should have:

ah its  not bad

Styling content

Time to have FUN! I love styling everything with CSS and I’m sure you’ll love it too :)

17. Open typography.css with your code editor. First, we need to choose a decent sans-serif font stack for the headlines. Find and change the following code in the CSS file:

h1, h2, h3, h4, h5, h6 {
font-style: normal;
font-family: Tahoma, Trebuchet, Geneva, Verdana, Helvetica, Arial, sans-serif;
margin:0;
padding:0;
}

18. Now we want to display our logo in two colors, make it change on hover, and give it a fixed size to protect the layout from browser resizing. Add the following code, right after the previous bunch of code:

#header h1 {
color: #8d8d8d;
text-transform: none;
font-size: 25px;
float: left;
margin: 0 20px 0 0;
line-height: 120px;
}

#header h1 a , #header h3 a{
color: #8d8d8d;
text-decoration: none;
}

#header h1 a:first-child {
color: #004987;
text-decoration: none;
}

#header h1:hover a,  #header h3 a:hover {
color: #6e6e6e;
}

#header h1:hover a:first-child {
color: #00284a;
}

#header h3 {
float: left;
color: #989898;
font-size: 12px;
line-height: 120px;
margin: 0;
}

This code features two neat tricks. The first one is to use line-height to vertically center some text (I like this trick). The second one is to put the “hover” property on the h1 tag, and NOT on the link itself. That way, you can create a bicolor link which react as a normal link!

19. Last thing to finish the header is to style the navigation. It’s often a mess (IE just won’t do what I ask him to).

Here is the CSS code:

#header ul {
list-style: none;
float: right;
margin: 0;
width: 485px;
}

#header li {
float: left;
width: 120px;
height: 119px;
border-right: 1px solid #cecece;
text-align: center;
line-height: 119px;
}

#header li:first-child {
border-left: 1px solid #cecece;
}

#header li:hover {
background: url(../images/layout/top-nav-focus.png) no-repeat center bottom;
}

#header li a {
padding: 0;
text-decoration: none;
text-transform: capitalize;
color: #666666;
}

#header li a:hover {
color: #00284a;
/* text-shadow: 0 0 3px #B7B7B7; */
}

Why is it better?

List elements are floated instead of the anchors tags (<a>). The whole code is way cleaner and uses up to date CSS properties. The text-shadow property adds a little softness to the links (uncomment it and see if you like).

20. Now that our header is appealing, we can concentrate on the content.

Change the body text color:

body {
color:#C8C8C8;
font: 13px/1.615385 Verdana, Helvetica, Arial, sans-serif;  /* Remove pixel size to enable font-size changed by browser */
}

Then find:

h2 {
font-size: 1.8461543em;
line-height: 0.875;
margin-top: 1.75em;
margin-bottom: 0.875em;
}

Change to:

h2 {
color: #ffffff;
font-size: 1.307692em;
line-height: 1.235294;
margin:1.235294em 0;
text-transform: uppercase;
}

h2 span.h2-color {
color: #9a9a9a;
}

#column-5 h2 {
margin-top: 0;
}

21. The lists are a total mess in Six Revisions’ tutorial, and I would be ashamed – as a web designer – if I dared to use something like that on a paid project. So, we are going to do better. Find the “Navigation & Lists” section and add the following code:

#column-1 ul {
list-style-type: none;
}

#column-1 li {
background: url(../images/layout/list-unordered.png) no-repeat -1px 5px;
float: left;
width: 172px;
padding: 0 5px 0 18px;
}

Why is it better?

The list background-image stays on the first line of the list, as it should. Moreover there is enough padding.

If you used Six Revisions’ layout and put too much content, very bad things would happen (again):

very bad things again

22. We are almost done! Stay strong :)

We can now style the sidebar. Add the following code:

#column-6 h3 {
font-size: 12px;
line-height: 19px;
text-transform: uppercase;
color: #ffffff;
text-align: center;
}

#column-6 ul {
margin-top: 14px;
}

#column-6 li {
font-size: 12px;
line-height: 18px;
list-style-type: none;
padding-top: 10px;
padding-bottom: 10px;
border-bottom: 1px solid #00172C;
border-top: 1px solid #002342;
}

#column-6 li:first-child{
border-top: none;
}

#column-6 li:last-child{
border-bottom: none;
}

Why is it better?

It’s always good to avoid using pictures when you can. One less picture is one less request to the server, and it’s easier to change pure CSS styles than redesign pictures with Photoshop. (And even if we used a :last-child selector, old browser will still display the list nicely.)

23. The footer is easy to style if we switch to the layout.css file. Find the footer styling and change it to:

#footer {
background: url(../images/layout/footer-bg.png) no-repeat center;
margin: 0 auto 20px auto;
width: 890px;
}

#footer>.inside {
text-align: center;
}

24. Last, yes last of the last, make sure everything is perfect. Delete the remaining default text (“Level-1 > Column-2″), write the meta tags, etc.

Here is the final result. Enjoy!

final result

If you want you can download the files here.

What now?

I hope you learnt many new things about workflow, clean markup, standard compliance and best practices in general.

When we read professional web designers’ articles and tutorials, we may find ourselves very small and unskilled. But they do mistakes too ^__^ (hopefully I’m not a pro yet). So, be confident!

Writing this tutorial took me 8 long hours (I mean the code took me 45min, but writing the tutorial itself was way harder… I wish English were my native tongue, really!). But I had fun.

Next time, I’ll write an article “better than” Smashing Magazine. So, be sure to grab the RSS and don’t miss it!

What do you think of this tutorial? Is it useful to you or do you think it is a waste of time? Any idea to make it better?

Please tell me!!!

Thank you.