Web Design Forum: TUTORIAL: Three column layout with background image - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

TUTORIAL: Three column layout with background image Two column layout with background image using Pure CSS Rate Topic: ***** 4 Votes

#1 User is offline   Sebastian Sulinski 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 24
  • Joined: 14-August 07
  • Reputation: 1
  • Location:Bognor Regis, UK
  • Experience:Web Guru
  • Area of Expertise:Web Designer

  Posted 14 August 2007 - 10:20 PM

Tutorial by: Sebastian Sulinski

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)

  • Attached File  back.gif (190bytes)
    Number of downloads: 96
  • Attached File  bullet.gif (49bytes)
    Number of downloads: 13

0

#2 User is offline   Ben 

  • Web Designer Forum Admin
  • View gallery
  • Group: Root Admin
  • Posts: 2,840
  • Joined: 24-August 06
  • Reputation: 102
  • Gender:Male
  • Location:Essex, UK
  • Experience:Intermediate
  • Area of Expertise:Web Designer

  Posted 14 August 2007 - 10:23 PM

Excellent tutorial Sebastian, well explained aswell.

A great starting block for creating CSS based layouts.

Thanks for taking the time to create it. :)
0

#3 User is offline   SEOLover 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 249
  • Joined: 10-January 07
  • Reputation: 0
  • Gender:Male
  • Location:Norwich, UK
  • Experience:Intermediate
  • Area of Expertise:SEO

  Posted 14 August 2007 - 10:29 PM

I love CSS and how you can achive a well structured design with mimimal code.

Nice tutorial
:clapping:
0

#4 User is offline   Sebastian Sulinski 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 24
  • Joined: 14-August 07
  • Reputation: 1
  • Location:Bognor Regis, UK
  • Experience:Web Guru
  • Area of Expertise:Web Designer

Posted 14 August 2007 - 11:10 PM

Thank you - I'm glad you like it.
0

#5 User is offline   BenG 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 766
  • Joined: 20-March 07
  • Reputation: 0
  • Location:Bradford, West Yorkshire
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 17 August 2007 - 07:18 PM

yer, thats wicked cool. :friends:
0

#6 User is offline   barsa 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 100
  • Joined: 31-March 08
  • Reputation: 2
  • Experience:Web Guru
  • Area of Expertise:Web Designer

Posted 17 May 2008 - 10:36 AM

very useful tutorial and also easy to understand this code
0

#7 User is offline   slooshy 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 14
  • Joined: 05-June 08
  • Reputation: 0
  • Experience:Nothing
  • Area of Expertise:I'm Learning

Posted 05 June 2008 - 06:41 PM

Thank you so much Sebastion for posting this tutorial. I have bought lots of books but none of them explain the three column layout as concisely as you have. For the first time I feel I am begining to understand.

Slooshy :D
0

#8 User is offline   telioswebdesign 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 22
  • Joined: 21-June 08
  • Reputation: 0
  • Location:Stoke on Trent
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 27 June 2008 - 11:01 PM

yeah, cool tutorial!
Sounds a bit easier now!
Cheers
0

#9 User is offline   craftedpixelz 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 644
  • Joined: 28-June 08
  • Reputation: 5
  • Gender:Male
  • Location:Manchester, UK
  • Experience:Web Guru
  • Area of Expertise:Web Designer

Posted 29 June 2008 - 12:39 PM

It's well explained and the outcome is good. Very nice indeed.
0

#10 User is offline   Sono Juventino 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 368
  • Joined: 17-March 08
  • Reputation: 0
  • Gender:Male
  • Location:Oslo, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 30 June 2008 - 03:07 AM

Wow. You should take a look on short-hand Css my friend. :)

body {
	font-size: 11px;
	font-family: Verdana, Arial, Helvetica, sans-serif;;
	color: #333333;
	text-align: center;
	margin: 0px;
	padding: 20px 0 20px 0;
}
#wrapper {
	width: 956px;
	padding: 10px;
	margin-top: 0 auto;
	height: auto;
	text-align: left;
	border: 1px solid #ddd;
}
#header {
	margin: 0px;
	padding: 0px;
	height: 100px;
	width: auto;
	background-color: #f1f1f1;
}
#container {
	padding: 0px;
	margin-top: 10px 0 0 0;
	background: url('back.gif') repeat-y top left;
	height: 1%;
	width: auto;
}
#left {
	margin: 0px;
	width: 160px;
	padding-top: 10px 20px 10px 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: url('bullet.gif') no-repeat top center;
}
#nav li a:link, #nav li a:visited, #nav li a:active {
	color: #666;
	text-decoration: none;
	display: block;
	margin: 0px;
	padding-top: 3px 15px 3px 15px;
	width: 130px;
}
#nav li a:hover {
	color: #999;
	text-decoration: none;
}
#center {
	height: auto;
	width: 504px;
	padding-top: 10px 20px 10px 20px;
	float: left;
	margin-top: 0px 0 0 6px;
	line-height: 1.8em;
}
h1 {
	font-size: 14px;
	margin: 0px;
	padding: 0px;
}
#right {
	padding-top: 10px 20px 10px 20px;
	height: auto;
	width: 160px;
	float: left;
	margin-top: 0px 0 0 6px;
}
.clearer {
	font-size: 0;
	line-height: 0;
	display: block;
	margin: 0;
	padding: 0;
	clear: both;
	height: 0;
	width: auto;
}
#footer {
	margin-top: 10px 0 0 0;
	text-align: center;
	padding-top: 15px 0 15px 0;
	background-color: #F1F1F1;
}
#footer p {
	color: #999;
	margin-top: 0px auto 0 auto;
	padding: 0px;
}
#footer a:link, #footer a:visited, #footer a:active {
	color: #999;
	text-decoration: none;
}
#footer a:hover {
	color: #ccc;
	text-decoration: none;
}


My lines: 109
Your lines: 151

You should also use a browser reset as IE, Firefox or other browsers will render this layout differently. * { margin: 0; padding: 0; } would allow you to drop 30-40 more lines of just resetting. :)

I don't want to "show-off" or anything, but shorthand CSS makes everything so much easier and it's even easier to understand and write code that way. Hope someone learned something by my example above. :)
0

#11 User is offline   anizot 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 19
  • Joined: 26-July 08
  • Reputation: 0
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 07 August 2008 - 07:37 AM

I've tried this layout www.triumphvillage.com
But this only works in internet explorer, it doesn't work in Firefox. Why is that? Can somebody help me to make this work in firefox as well? thanks
0

#12 User is offline   Duck 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 380
  • Joined: 07-February 08
  • Reputation: 0
  • Gender:Male
  • Location:Cirencester - Gloucestershire
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 07 August 2008 - 12:17 PM

Good Tut old chap! :lol:

@Sono - I see your point but your css does not work.
0

#13 User is offline   Sono Juventino 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 368
  • Joined: 17-March 08
  • Reputation: 0
  • Gender:Male
  • Location:Oslo, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 08 August 2008 - 01:04 AM

I might've done something wrong when cutting into Sebastian's code, but I don't think that is the reason.

I think the reason is that Sebastian does not use any kind of browser resetting, which forces him to write code that deals with that. Browser resetting is vital if you want your site to behave the same way in all browsers. This is why I always use Eric Meyer's CSS reset and I recomend you to do to. You might need to rebuilt your layout if you go for Meyer's method, but I would say it's totaly worth it. So yes.

Bottom line. Short-line Css is good practise. If my version is rendered different than Sebastians, that's because I've also removed CSS defaults, like background-attachment: scroll;. Poor browsers like IE6 might use something else as a default value. Do you understand, or did I make it worse. :lol:
0

#14 User is offline   Duck 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 380
  • Joined: 07-February 08
  • Reputation: 0
  • Gender:Male
  • Location:Cirencester - Gloucestershire
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 08 August 2008 - 02:20 PM

Ok, I see what you mean! ;) - your way would make less need for separate CSS for ie6 etc.
0

#15 User is offline   Sono Juventino 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 368
  • Joined: 17-March 08
  • Reputation: 0
  • Gender:Male
  • Location:Oslo, Norway
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 08 August 2008 - 04:15 PM

Exactly. ;)
0

#16 User is offline   Sam Christy 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 357
  • Joined: 23-August 08
  • Reputation: 0
  • Location:South London, England
  • Experience:Beginner
  • Area of Expertise:Designer/Coder

Posted 04 October 2008 - 03:03 PM

Nice clear tutorial! :D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users