Difficulty:Tricky in places

Version:Expression Engine 1.0: 20040424

Buy My Book!

Update July 2008: If you like these tutorials and would like to read more like these, except updated for ExpressionEngine 1.6 and with tons more information, tips, tricks and recommendations, check out my new book, Building Websites with ExpressionEngine 1.6. Available either directly from Packtpub.com or from your local online bookstore (such as Amazon), this book uses the same clear, step-by-step approach found in these tutorials and walks you from the basics of installing ExpressionEngine to everything you need to know to have an ExpressionEngine website you can be proud of. (No prior knowledge of ExpressionEngine assumed).

The toasty website after this tutorial is complete, following path A!
The toasty website after this tutorial is complete, following path B!
The toasty website after this tutorial is complete, following path C!

This tutorial is going to show you how to improve your own personal webpage using basic CSS, developing your knowledge of templates as we go on. If you’ve followed tutorial 1, you’ll have a plain HTML page with some text. The bits of text should all be logically identified using <div> tags - this tutorial depends upon that. Now, I’m going to show you how to make your boring old HTML page look good. 

Background Information

Once upon a time, a HTML page used to contain everything in one place. Each HTML file not only contained the text you wanted to display, but lots of information about how you wanted the text to look. When you only have one or two pages, this isn't a problem. But imagine if you have 50 pages that all look the same. Now, imagine you want to change the colour of your heading. Yes, that's right. You'd have to change it in 50 different places. To combat this, CSS was invented. A CSS file contains all the information needed to make your page look pretty. And, if you have 50 pages that are all similiar, you can use the same CSS file throughout. Right now, we're going to write a CSS file for our HTML page. However, to demonstrate the versatility of CSS, I'm going to write 3 CSS files, showing you how the same page can look completely different. When writing in CSS, it's important to note that different browsers and different operating systems can make the same page look completely different. If you use Safari on the Mac to design your page, you may be shocked to find that Internet Explorer for Windows completely ruins your page. As you write, you may want to use a resource like Browser Photo to view what your website looks like in a variety of alternative browsers. Finally, I can only show you how to write CSS for a basic site in Expression Engine. There are lots of sites with far more information about CSS than I could possibly teach you. To appreciate the full power of CSS, the CSS Zen Garden uses 1 HTML file and displays it in an astounding variety of ways. CSS Layout Techniques offers a selection of excellent CSS examples, as well as lots of other resources for the CSS newcomer.

Instructions

Add a new template...

Think of a template group as a home where your HTML and your CSS can live together in perfect harmony...

Create a new template...

Edit your index template...

Many people have found this step to be quite a headache. If you're stuck, check out the comments (link at the bottom of the page) for some suggestions that may help. For example, you may need to set the 'type of template' option as CSS in step 2...

Remember that code in green is used to indicate code that already exists. You can also roll over the new code for additional explanations...

<title>Toast!</title>

<link rel='stylesheet' type='text/css' media='all' href='{stylesheet=site/css}' />

<style type='text/css' media='screen'>@import "{stylesheet=site/css}";</style>

</head>


Editing your index template...

Try to make sure you always save revisions of your templates. That way, if you do something really terrible (and lets face it, we all do), you can just replace it with an earlier revision...


Editing your css template...

The HTML components

Not seeing any changes at all? Then your HTML file may not know where your CSS file is. Return to step 4, and be sure to specify the exact template group and template name for your CSS template.

h1

{

font-family: Arial, Helvetica, sans-serif;

font-size: 125%;

}

h2

{

font-family: Arial, Helvetica, sans-serif;

font-size: 120%;

font-weight: bold;

}


Woah! What are these '#' symbols? Briefly, it applies to any part of your HTML that has the 'id' attribute. So you might have #goat { text-align: center; }, and any element that has an 'id=goat' attribute would be centered. For a more complete explanation of CSS structure and rules, visit www.htmlhelp.com.

#content

{

font-family: Verdana, "Trebuchet MS", Arial, Helvetica, sans-serif;

font-size: 80%;

}

#footer

{

font-family: Verdana, "Trebuchet MS", Arial, Helvetica, sans-serif;

font-size: 65%;

}

Remember you don't have to replicate my site exactly. Perhaps Verdana isn't your favourite font, or you like your text just a little bit bigger? Go ahead! Be different!


body

{

margin-left: 5%;

margin-right: 5%;

}

h1

{

font-family: Arial, Helvetica, sans-serif;

font-size: 125%;

margin-top: 25px;

margin-bottom: 25px;

}

h2

{

font-family: Arial, Helvetica, sans-serif;

font-size: 120%;

font-weight: bold;

}

p

{

margin-top: 5px;

margin-bottom: 5px;

}

#header

{

padding: 0;

margin: 0;

text-align: left;

}

#content

{

font-family: Verdana, "Trebuchet MS", Arial, Helvetica, sans-serif;

font-size: 80%;

padding: 5px 5px 5px 5px;

}

#footer

{

font-family: "Verdana","Arial","Helvetica",sans-serif;

font-size: 65%;

text-align: left;

}

Notice how I've tried to order my CSS file. At the top are the HTML tags, followed by my own <div> tags. The tags themselves are ordered in the order they appear on the page. This is to make it easier as the CSS file grows...

Follow either path a, b or c but if you mix them up, you may get different results to me...


body

{

margin-left: 5%;

margin-right: 5%;

background: #fff url('http://www.leoandmeg.com/images/toasty.jpg') no-repeat top center;

}

#header

{

padding: 0;

margin: 0;

text-align: left;

background: url('http://www.leoandmeg.com/images/uploads/toastcenter.png') no-repeat top center;

height: 7em;

}

#header

{

padding: 0;

margin: 0;

text-align: left;

background: url('http://www.leoandmeg.com/images/uploads/toastleft.png') no-repeat top left;

height: 10em;

}


#content

{

font-family: "Verdana", "Trebuchet MS","Arial","Helvetica",sans-serif;

font-size: 80%;

padding: 5px 5px 5px 5px;

background-color: #fff;

}

In paths 12b and 12c, we hide the h1 text. However, this means that any text you write in <h1> tags will be hidden. This is okay though because you're not supposed to use two of the same heading in the same page. Instead, you should style another heading (in this case <h2> to look like a <h1> heading...

h1

{

font-family: Arial, Helvetica, sans-serif;

font-size: 125%;

margin-top: 25px;

margin-bottom: 25px;

display: none;

}


At this stage you will find the instructions aren't applicable to your exact site. You will need to experiment with the tags I have told you to get the effect you want...

#footer

{

font-family: "Verdana","Arial","Helvetica",sans-serif;

font-size: 65%;

text-align: left center;

border-top: 1px solid #999;

}


#footer

{

font-family: "Verdana","Arial","Helvetica",sans-serif;

font-size: 65%;

background-color: transparent;

text-align: left;

position: absolute;

top: 0px;

margin-top: 54em;

width: 19em;

}

#content

{

font-family: Verdana, "Trebuchet MS", Arial, Helvetica, sans-serif;

font-size: 80%;

padding: 5px 5px 5px 5px;

margin-left: 10em;

}

#footer

{

font-family: "Verdana","Arial","Helvetica",sans-serif;

font-size: 65%;

text-align: center;

border-top: 1px solid #999;

margin-left: 10em;

}


h2

{

font-family: Arial, Helvetica, sans-serif;

font-size: 120%;

font-weight: bold;

border-top: 5px solid #999;

border-bottom: 5px solid #999;

}

My site with the different zones (header, content and footer) coloured in red, yellow and green

Summary

There are lots of resources out there to help you as you begin your journey with CSS. A good start is www.pmachine.com which has lots of links to CSS templates you can adapt as your own. You can find some example templates at pmtemplate.kartar.net. Finally, if you stuck, www.pmachine.com also hosts a design forum where you can post your questions and queries. 

In our next tutorial, we’ll write a second page using the same CSS file and link to it.

Got something to add? Add your comment to the 13 already made

Written by Leonard on Tuesday 4th May 2004