The Brave Programmer - Blogging and coding
Not for the faint hearted
 

Blog Posts From The Brave Programmer

Minimize

Creating a Pure CSS layout

May7

Written by:
2009/05/07 01:23 PM RssIcon

CSS LayoutWebsites and web development software were never meant for desktop publishing. Because of this there were certain limitations that had to be worked around. One of them being layout. In DTP, you could easily layout your copy with little effort. But for the web this is not so.

Traditionally webmasters have been able to achieve website layouts with the use of tables. But tables are very cumbersome and heavy, as well as having their own set of problems. Nowadays the preferred method is to use CSS for layout. But moving to something new is often scary. If we take the move a little at a time then it will all be manageable and less daunting.

Today we are going to look at creating a simple website layout using pure CSS. If you do not know CSS stands for Cascading Style Sheets.

So why would anyone want to or need to go the CSS layout route. CSS is easier for search engines to read and index. If you are serious about SEO, then you should consider CSS layouts for your website. Complicated table layouts can become a nightmare to maintain and update. Most time CSS code can be a lot lighter than table layout code, making your site just that bit faster to download.

Tables are not evil. They do have a purpose within standards based web design (for the display of tabular data); however, if at all possible, you should not use them to create the main layout of an html page.

The main tag we use in a CSS layout is the < div> tag. Within the div tag, we can use properties and values to describe the div element. This can be very powerful. We can change size, position, colour, almost anything you want within the CSS rules.

We are going to design a simple 2 column layout with a header and footer. We start with the basic HTML mark-up. Then within the body tag, we will make use of the div element. Our finished layout will look something similar to the diagram below:

 Header
Navigation Content
Footer

 

The basis of the layout is the div element. Below is the basic structure.

<div id="container">
<div id="header">
div>
<div id="wrapper">
<div id="content">
div>
div>
<div id="navigation">
div>
<div id="footer">
div>
div>

The div elements are rendered from top to bottom. Leaving the elements as they are will just render them in a paragraph fashion. From top to bottom. By default the div element will fill its own container to 100%.  If the content is smaller, it will resize to suite.

The header and footer div elements will be left as they are, because there is no specific arrangements that need tweaking. What we want is the Navigation div element to be on the left of the Content element. To do this we use a fantastic property called the float property. The float property has three possible values, left;right; none. When left or right property is used, the element is arranged to line up flush with the next or previous element in the DOM.

We wrap the content element in another div wrapper for ease of use. You do not have to do this, but it makes life simpler when adding other elements, like more divs, to the content div element. It is this div element that we add the floating property to with a value of “right”, and we will add a width percent value.

To do this we add a CSS rule:

div#wrapper {
float:right;
width:70%
}

This will float the “Wrapper” container and everything in it to the right most position relative to any other elements. Now we need to do something similar for the navigation, but this time we will float left, and add a width percentage.

div#navigation {
float:left;
width:29.9%
}

The next thing to do is to make sure that the Footer div element does not inherit any positioning. We employ the following rule to the footer element.

div#footer {
clear:both;
width:100%;
}

We have wrapped everything inside a Div container. The only thing left now is to add any other styling that suites your website. Like padding, line height, margins, etc. The final code could look like below. I hope you enjoy.

You can also navigate to http://layouts.ironmyers.com/ for more Free CSS layouts to download.

The CSS and HTML code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<title>Css Layout</title>

<meta http-equiv="content-type"

content="text/html; charset=iso-8859-1">

<style type="text/css">
html, body {
margin:0;
padding:0
}
body {
font: 76% arial, sans-serif
}
p {
margin:0 10px 10px
}
a {
display:block;
color: #981793;
padding:10px
}
div#header h1 {
height:80px;
line-height:80px;
margin:0;
padding-left:10px;
background: #EEE;
color: #79B30B
}
div#content p {
line-height:1.4
}
div#navigation {
background:#B9CAFF
}
div#extra {
background:#FF8539
}
 
 
div#wrapper {
float:right;
width:70%
}
div#navigation {
float:left;
width:29.9%
}
 
div#footer p {
margin:0;
padding:5px 10px
 
}
div#footer {
background: #333;
color: #FFF;
clear:both;
width:100%;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<h1>Header</h1>
</div>
<div id="wrapper">
<div id="content">
</div>
</div>
<div id="navigation">
</div>
 
<div id="footer">
</div>
</div>
</body>
</html>

 

 

Technorati Tags: ,,

Tags:
Categories:
blog comments powered by Disqus
 
Blog Updates Via E-mail
 Blog Updates Via E-mail
Minimize

Do you want to receive blog updates via e-mail. Then just click on the link below. You will be redirected to Google's feed burner, where you can fill out a form. Supplying your e-mail address.

The subscription is managed entirely by Google's Feedburner. We cannot and do not collect your email address.

Subscribe to The Brave Programmer by Email

Print  
 

 

Latest Comments
 Latest Comments
Minimize
Powered by Disqus

Sign up with Disqus to enjoy a  surprise box of features

Print  
 
Blog Roll
 Blog Roll
Minimize
Print  
 
Categories
 Categories
Minimize
Print  
 
<h1>Search Blogs From The Brave Programmer</h1>
 

Search Blogs From The Brave Programmer

Minimize
Print  
 
Archive
 Archive
Minimize
Archive
<December 2024>
SunMonTueWedThuFriSat
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234
Monthly
Go
Print  
 
<h1>News Feeds (RSS)</h1>
 

News Feeds (RSS)

Minimize
Print  
 

Follow robertbravery on Twitter

Blog Engage Blog Forum and Blogging Community, Free Blog Submissions and Blog Traffic, Blog Directory, Article Submissions, Blog Traffic

View Robert Bravery's profile on LinkedIn

Mybyte

 

Robert - Find me on Bloggers.com

Tags
 Tags
Minimize
Print  
 
Contact Us Now
 Contact Us Now
Minimize
 

Email  us now or call us on 082-413-1420,  to host your website.

We design and develop websites. We develop websites that make a difference. We do Dotnetnuke Module development.

Web Masters Around The World
Power By Ringsurf
Print