Creating A CSS Powered Site
Creating A CSS Powered Site
Introduction
This guide will help you create your own webpage
coded in html and styled using CSS (Cascading
Style Sheets). Modern web design software can
handle all of the CSS for you, but it is good
practice to delve into the code as then you can
start to appreciate how it all works.
What is CSS?
CSS stands for Cascading Style Sheets. They were introduced to help streamline
websites by allowing designers to define styles. These could then be repeated
across an entire website with multiple pages. The styles allow a webpage designer
control over layout, fonts, colours, navigation – it keeps the presentation separate
from the actual content.
The screenshots shown here are from Dreamweaver CS5, but you can use any
program you like – you can code even in the most basic text editor such as
Notepad.
What are we creating exactly?
You are going to create a webpage like this – which you can then customise and
develop into your own masterpiece.
The navigation bar near the top uses CSS to provide hover-over effects:
As you develop the page, you can customise the colours, presentation and
everything else – this is the beauty of using CSS to design a website. It keeps the
content and the design neatly separated.
This basic page has a CSS header, a block of dark colour across the whole page
including the navigation bar. There is also a section for the main content within
the dark box - here you will setup two columns to help organise your content.
There is also a footer section at the bottom of the page.
Don’t worry –
we’ll work
through all this…
1. Load your program of choice and make sure you can edit code directly.
For example, if you are using Dreamweaver, load the program, select ‘File’
and ‘New’. Click on the option to create a basic .html file.
The DOCTYPE note is to tell the web browser what type of html code is
being used.
The <head> tag is used to setup the page – things like the title, CSS style
information and additional code that needs used in the page.
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
<title>Untitled Document</title> <head> tag
</head>
</html>
4. We now need to setup the CSS code for the starter website. This is more
complex code, but this time you need to actually add it yourself. It is the
best way to start becoming familiar with the way CSS code is structured.
We need to ‘define’
a series of styles.
5. Add (type – don’t copy and paste) the following text underneath the:
<title>Untitled document</title>
<style type="text/css">
body {
font-family: Geneva, Arial, Verdana, sans-serif;
font-size: 13px;
background: #fff;
margin:0;
}
The <style> tag is the way we can add CSS code directly to a webpage.
The body { } section is where we define how the main ‘body’ of the
webpage will look – we set the default font, the font size and
background colour.
6. Next add the following CSS code. You can copy and paste it this time.
p {
margin: 0 0 18px;
line-height: 18px;
font-size: 13px;
}
a {
color:#00F;
font-weight: normal;
text-decoration: underline;
}
a:hover {
color:#F00;
}
h1 {
font-weight: bold;
font-size: 26px;
color: #383226;
margin: 0 0 6px;
}
h2 {
font-weight: bold;
font-size: 56px;
color: #383226;
margin: 0 0 6px;
}
Here we have defined how default paragraph will look – the p { … } style
The a { … } style refers to hyperlinks. The colour used for links, the colour
shown when you hover over the link.
p { … } = paragraphs
a { … } = hyperlink behaviour
h1 { … } and h2 { … } = header text
8. We now need to setup the layout of the page. This is where you can define
different sections such as a place for text or an image at the top of a page,
a navigation bar and a section for all the main content to appear.
We are going to define our own custom styles to use on the page. Add this
code to your webpage.
/* Layout */
div.wrapper {
width: 978px;
overflow: hidden;
margin: 0 auto;
}
div.top {
width: 952px;
height: 70px;
padding: 10px;
overflow: hidden;
}
div.main {
background:#600;
overflow: hidden;
padding: 0 0 40px;
}
div.navigation {
clear: both;
background:#600;
overflow: hidden;
padding: 0;
}
div.main div.wrapper {
padding: 0 20px 26px 10px;
width: 942px;
background:#FFC;
}
div.column {
width: 442px;
padding: 22px 0 0;
overflow: hidden;
}
div.left {
float: left;
padding-left: 16px;
}
div.right {
float: right;
}
div.footer {
padding: 10px;
overflow: hidden;
}
/* Navigation bar */
ul#nav {
padding: 0;
margin: 0 auto;
width: 980px;
list-style: none;
list-style-image: none;
}
ul#nav li {
display: block;
list-style: none;
list-style-image: none;
float: left;
margin: 0;
padding: 0 12px;
}
ul#nav li a {
overflow: hidden;
height: 40px;
display: block;
padding: 0 12px;
line-height: 40px;
float: left;
margin: 0;
font-size: 15px;
color: #fff;
text-decoration: none;
text-transform:uppercase;
}
ul#nav li a:hover {
background: #fff;
color: #f00;
}
</style>
10. This code takes a standard bullet list (the li code) and customises it to
create a horizontal navigation bar. This shows the power of CSS. To find
out what it actually does, we need to experiment with it on our actual
page.
11. Make sure you have added the code to the correct place. All CSS code
needs to be within the <head> tag of your webpage.
If it is in the correct place, you should see the final lines of the CSS code,
ending with </style> followed by the </head>. The slashes are what html
uses to close a tag.
12.The main content can now be added to the <body> section. Here we will
make use of all the custom CSS styles we have created.
<div class="wrapper">
<div class="top">
<h2>Website name</h2>
</div>
</div>
13.Save your webpage and view it in your browser. If you are using
Dreamweaver, you can use the ‘File’ > ‘Preview in browser’ option.
14.Next we can add the navigation html code. Without the CSS this would
appear as a vertical bullet point list.
The <a href code refers to the hyperlinks for your navigation bar. At the
moment they are just blank, but we’ll need to change them to actual page
links eventually.
<div class="navigation">
<ul id="nav">
<li><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
<li><a href="#">Page 4</a></li>
<li><a href="#">Page 5</a></li>
<li><a href="#">Page 6</a></li>
</ul>
</div>
16.Finally, we need to add the code for our main content and ‘footer’:
<div class="main">
<div class="wrapper">
<div class="left column">
<h1>Homepage</h1>
<p>Text on the left</p>
</div>
<div class="right column">
<p>Placeholder for images or text on the
right</p>
</div>
</div>
</div>
<div class="wrapper">
<div class="footer">
Footer appears here
</div>
</div>
Please.
No more code?!
What an idiot –
we’re just
getting started…
17.Preview your page and you should see something very similar to this:
If your page doesn’t look like this you need to go back and check your html code.
You may have pasted or typed code into the wrong place.
The code at the end of your page should look like this:
?
Think about some of these issues and suggestions:
o Save your current work before you experiment too much – experiment with
a new copy of the page.
o The best sites don’t actually have the CSS code within each page, they link
to a separate file. Research ‘external style sheets’ and see if you can…
o For your own website, you need to create pages before you can link to
them. You could create one page you’re happy with and then duplicate it.
o This is very much about you taking total ownership of this work – you’ve
been given a start, but now be confident to adapt it, change it and create
your own genius piece of web design.
Come on…
Get on with it.