I will be showing you how to make a very simple but effective three column layout.
First we will begin with the HTML, or structure, of our three column layout.
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
-
-
-
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
-
-
-
<head>
-
<title></title>
-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
-
<link rel="stylesheet" href="style.css" />
-
</head>
-
-
<body>
-
-
<div id="left">
-
</div>
-
-
<div id="middle">
-
</div>
-
-
<div id="right">
-
</div>
-
-
</body>
-
-
</html>
Depending upon what you're using each column for there are two ways to position our divisions. We will start with the easier one first.
For this exmaple we are actually going to change our HTML a little. Instead of using ids for our divisions we are going to give them all the same class. So our HTML should look like this.
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
-
-
-
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
-
-
-
<head>
-
<title></title>
-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
-
<link rel="stylesheet" href="style.css" />
-
</head>
-
-
<body>
-
-
<div class="column">
-
</div>
-
-
<div class="column">
-
</div>
-
-
<div class="column">
-
</div>
-
-
</body>
-
-
</html>
The reason we're giving each division the same class is so it will be easier to give them all the same style from one rule.
Now we will begin with the CSS, or styles, for our three column layout.
- .column {
-
float:left;
-
width:200px;
-
height:500px;
-
border:1px solid #000;
-
}
The most important style here is the "float:left;". This is what makes each division sit perfectly against one another. It's really all you need to make a three column layout. The other styles are simply for visual aid. It's very simply but it does cost some customability of each division. This is where our second example comes into play.
Now we switch back to our first code.
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">
-
-
-
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
-
-
-
<head>
-
<title></title>
-
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
-
<link rel="stylesheet" href="style.css" />
-
</head>
-
-
<body>
-
-
<div id="left">
-
</div>
-
-
<div id="middle">
-
</div>
-
-
<div id="right">
-
</div>
-
-
</body>
-
-
</html>
Each division having its own id makes it much easier to add specific styles to that, and only that, division. We're still going to use the same styles for each division and we do have to type a little more code, but it's worth it for customability of each division.
- #left {
-
float:left;
-
width:200px;
-
height:500px;
-
border:1px solid #000;
-
}
-
-
#middle {
-
float:left;
-
width:200px;
-
height:500px;
-
border:1px solid #000;
-
}
-
-
#right {
-
float:left;
-
width:200px;
-
height:500px;
-
border:1px solid #000;
-
}
Now you know two ways to make a three column layout, simply by using the powerful style "float:left;".