HTML/CSS - 3 Column Page Layout

1 post Page 1 of 1
Contributors
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

HTML/CSS - 3 Column Page Layout
Scottie1972
OK, this is a simple 3 column html page layout with 5 sections.

Section 1: Header
Section 2: Left Column
Section 3: Center Column
Section 4: Right Column
Section 5: Footer


The CSS
Code: Select all
<style type="text/css">
body{
	margin:0;
	padding:0;
	line-height: 1.5em;
}

b{font-size: 110%;}
em{color: red;}

#wrapper{
	width: 840px;
	margin: 0 auto;
}

#header{
	background: #ff4800;
	height: 90px;
}

#header h1{
	margin: 0;
	padding-top: 15px;
}

#contentmain{
	float: left;
	width: 100%;
	background: #fff1b9;
}

#maincolumn{
	margin: 0 190px 0 180px;
}

#leftcolumn{
	float: left;
	width: 180px;
	margin-left: -839px;
	background: #fff1b9;
	border-right: 1px solid #000000;
}

#rightcolumn{
	float: left;
	width: 190px;
	margin-left: -191px;
	background: #fff1b9;
	border-left: 1px solid #000000;
}

#footer{
	clear: left;
	width: 100%;
	background: #ff4800;
	color: #fff;
	text-align: center;
	padding: 4px 0;
}

#footer a{
	
}

.inner{
	margin: 10px;
	margin-top: 0;
	height:400px;
}

</style>
The HTML
Code: Select all
<body>
	<div id="wrapper">
		<div id="header"><div class="innertube"><h1>CSS 3 Column Layout</h1></div></div>
			<div id="contentmain">
				<div id="maincolumn">
					<div class="inner"><b>Content Column:</b></div>
				</div>
			</div>
			<div id="leftcolumn">
				<div class="inner"><b>Left Column:</b></div>
			</div>
			<div id="rightcolumn">
				<div class="inner"><b>Right Column:</b></div>
			</div>
		<div id="footer"><a href="http://www.codenstuff.com">Codenstuff.com</a></div>
	</div>
</body>
The Fully coded page
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CSS 3 Column Layout</title>
<style type="text/css">
body{
	margin:0;
	padding:0;
	line-height: 1.5em;
}

b{font-size: 110%;}
em{color: red;}

#wrapper{
	width: 840px;
	margin: 0 auto;
}

#header{
	background: #ff4800;
	height: 90px;
}

#header h1{
	margin: 0;
	padding-top: 15px;
}

#contentmain{
	float: left;
	width: 100%;
	background: #fff1b9;
}

#maincolumn{
	margin: 0 190px 0 180px;
}

#leftcolumn{
	float: left;
	width: 180px;
	margin-left: -839px;
	background: #fff1b9;
	border-right: 1px solid #000000;
}

#rightcolumn{
	float: left;
	width: 190px;
	margin-left: -191px;
	background: #fff1b9;
	border-left: 1px solid #000000;
}

#footer{
	clear: left;
	width: 100%;
	background: #ff4800;
	color: #fff;
	text-align: center;
	padding: 4px 0;
}

#footer a{
	
}

.inner{
	margin: 10px;
	margin-top: 0;
	height:400px;
}

</style>
</head>
<body>
	<div id="wrapper">
		<div id="header"><div class="innertube"><h1>CSS 3 Column Layout</h1></div></div>
			<div id="contentmain">
				<div id="maincolumn">
					<div class="inner"><b>Content Column:</b></div>
				</div>
			</div>
			<div id="leftcolumn">
				<div class="inner"><b>Left Column:</b></div>
			</div>
			<div id="rightcolumn">
				<div class="inner"><b>Right Column:</b></div>
			</div>
		<div id="footer"><a href="http://www.codenstuff.com">Codenstuff.com</a></div>
	</div>
</body>
</html>
Image

Now dealing with column driven webpages using css is a pain.
Say you want to add a border to one of the section. Well you can, but it will throw off the layout of the page.
So if you add a border to the Left or Right or Center column, you will have to adjust the Margin of the CSS for that element as well.
Image
1 post Page 1 of 1
Return to “Tutorials”