In this tutorial I will explain how to design three column layout using pure css (table-less layout) and background image.
Demo is available here.
To start with let's create a structure of our page. Please copy and paste the following content into your page:
<div id="wrapper"> <div id="header"></div> <div id="container"> <div id="left"> <ul id="nav"> <li><a href="#" title="home">home</a></li> <li><a href="#" title="about us">about us</a></li> <li><a href="#" title="services">services</a></li> <li><a href="#" title="portfolio">portfolio</a></li> <li><a href="#" title="testimonials">testimonials</a></li> <li><a href="#" title="contact us">contact us</a></li> </ul> </div> <div id="center"> <h1>Title Placeholder</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p> </div> <div id="right">Some content</div> <div class="clearer"> </div> </div> <div id="footer"><p>© <a href="http://www.sebastiansulinski.co.uk/" title="Freelance Web Designer" target="_blank">Freelance Web Designer</a> </p> </div> </div>
Now our CSS:
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #333333;
text-align: center;
margin: 0px;
padding-top: 20px;
padding-right: 0px;
padding-bottom: 20px;
padding-left: 0px;
}
#wrapper {
width: 956px;
padding: 10px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
height: auto;
text-align: left;
border: 1px solid #DDDDDD;
}
#header {
margin: 0px;
padding: 0px;
height: 100px;
width: auto;
background-color: #f1f1f1;
}
#container {
padding: 0px;
margin-top: 10px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
background-attachment: scroll;
background-image: url(back.gif);
background-repeat: repeat-y;
background-position: 0px 0px;
height: 1%;
width: auto;
}
#left {
margin: 0px;
width: 160px;
padding-top: 10px;
padding-right: 20px;
padding-bottom: 10px;
padding-left: 20px;
float: left;
}
#nav {
margin: 0px;
padding: 0px;
list-style-image: none;
list-style-type: none;
}
#nav li {
margin: 0px;
padding: 0px;
display: block;
background-attachment: scroll;
background-image: url(bullet.gif);
background-repeat: no-repeat;
background-position: 0px 50%;
}
#nav li a:link, #nav li a:visited, #nav li a:active {
color: #666666;
text-decoration: none;
display: block;
margin: 0px;
padding-top: 3px;
padding-right: 15px;
padding-bottom: 3px;
padding-left: 15px;
width: 130px;
}
#nav li a:hover {
color: #999999;
text-decoration: none;
}
#center {
height: auto;
width: 504px;
padding-top: 10px;
padding-right: 20px;
padding-bottom: 10px;
padding-left: 20px;
float: left;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 6px;
line-height: 1.8em;
}
h1 {
font-size: 14px;
margin: 0px;
padding: 0px;
}
#right {
padding-top: 10px;
padding-right: 20px;
padding-bottom: 10px;
padding-left: 20px;
height: auto;
width: 160px;
float: left;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 6px;
}
.clearer {
font-size: 0px;
line-height: 0px;
display: block;
margin: 0px;
padding: 0px;
clear: both;
height: 0px;
width: auto;
}
#footer {
margin-top: 10px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
text-align: center;
padding-top: 15px;
padding-right: 0px;
padding-bottom: 15px;
padding-left: 0px;
background-color: #F1F1F1;
}
#footer p {
color: #999999;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
padding: 0px;
}
#footer a:link, #footer a:visited, #footer a:active {
color: #999999;
text-decoration: none;
}
#footer a:hover {
color: #CCCCCC;
text-decoration: none;
}Ok - so what actually has happened?
Our entire layout is "wrapped" in the outside div with id="wrapper"
The width of the wrapper is 956px plus it has 10px padding on each side.
I have also added a 1px border to create the outline of our div against white background of the body tag.
Next element is a div with id="header"
This is just a simple header with height of 100px.
Next element in the hierarchy is div with id="container".
Container has margin and padding equal 0 plus - to satisfy our Internet Explorer we had to add it 1% height.
Without this, background image wouldn't be visible in this rather not very friendly browser.
Container also has a background image which you can download underneath.
This image is repeated vertically so regardless of the height of any of the element inside of the container the background image will fill in the the entire space vertically and horizontally.
Inside container I have created four divs with ids: #left, #center, #right and a class .clearer.
All of them except .clearer have float=left to ensure they are in line.
center and right divs have also left margin of 6px to give a gap in between the columns.
.clearer has font-size, line-height, margin, padding and height equal 0 and clear equal both.
This way it seperates our divs from what's after .clearer.
Then it's just footer and some simple formatting - feel free to change copyright to anything you want.
I hope you'll enjoy this tutorial.
Attached File(s)
-
back.gif (190bytes)
Number of downloads: 96 -
bullet.gif (49bytes)
Number of downloads: 13
Help
























