2003 - (Sitepoint) Exploring The Limits of Css Layout (9 Pages)
2003 - (Sitepoint) Exploring The Limits of Css Layout (9 Pages)
2003 - (Sitepoint) Exploring The Limits of Css Layout (9 Pages)
Kevin Yank
minded Web developers. Kev believes that any good Webmaster should
Kevin Yank has written 66 articles for SitePoint with an average reader
rating of 8.9.
By Kevin Yank
With major sites like Wired News and ESPN migrating to CSS layout,
the "new wave" of Web design is truly here. But even in the most
Understanding them can save you a lot of frustration and wasted time.
For better or worse, the vogue of Web design has evolved to favour a layout
That last one is the real kicker. The sad reality is that the current CSS
mind. As a result, just as Web designers have always had to abuse HTML
tables to achieve complex page layout, they must now abuse CSS
This is a controversial position to take, I'll admit. Right now, all signs point
to CSS as the ideal way to perform page layout for the Web. Unfortunately,
present day Web design, the strong fashion of multi-column design chief
among them.
Shown here is the classic three column design with header and footer, the
most basic expression of current Web layout fashion. This is of course dead
easy to accomplish with HTML tables, but you're better than that!
incidentally, are simply <div> tags in the HTML code. By "natural" I mean
that we don't do anything special to the blocks to get them into this layout
-- the browser will naturally stack the three blocks vertically, each occupying
Next, we make room for the left and right columns by adding margins to the
#content {
margin-left: 100px;
margin-right: 100px;
#left, #right {
position: absolute;
width: 100px;
#left {
left: 0;
#right {
right: 0;
Not far from the desired effect, right? There are just two problems with this
result:
● The left and right columns do their own thing in the height
department. CSS provides no way to match the heights of the
columns without setting a fixed height for all three -- rarely a
feasible option!
● Since the absolute-positioned left and right columns float above the
rest of the page, the position of the footer is still determined solely
by the height of the content area. This causes problems when the
content column is shorter than the other columns.
If you're dealing with solid background colors in all the columns, the former
may not be a problem for you. The latter, however, is the biggest headache
For now, the best solution is to use JavaScript to equalize the column
We'll assume you have a page with three columns. The center column uses
natural (i.e. static) positioning and includes margins that leave room for the
The id attributes of the column <div> tags are left, content, and right.
Simply download x.js from that site and load it in the <head> tag of your
page as follows:
</script>
Now, because the footer may well be covered by the left and right columns
when the browser lays them out, we'll want to keep the footer invisible until
Make sure the footer <div> has id="footer" set and add this style rule to
<style type="text/css">
#footer {
visibility: hidden;
</style>
Now, when the browser has finished loading the page (and whenever the
browser window is resized), we want to find out which of the columns is the
tallest and resize them all to that height. Then we can display the footer.
Because this process may happen repeatedly as the user resizes the browser
<div id="left">
<div id="leftcontent"><!--left--></div>
</div>
<div id="content">
<div id="contentcontent"><!--content--></div>
</div>
<div id="right">
<div id="rightcontent"><!--right--></div>
</div>
It is these "inner" <div> we will check for the natural height of each column
Here's the JavaScript function that adjusts the layout using the X library's
<script type="text/javascript">
function adjustLayout()
var maxHeight =
xHeight("content", maxHeight);
xHeight("left", maxHeight);
xHeight("right", maxHeight);
xShow("footer");
All that's left is to make this function run when the page is loaded or resized.
window.onload = function()
xAddEventListener(window, "resize",
adjustLayout, false);
adjustLayout();
</script>
The Future
But how about the future? The working draft of CSS3 includes multi-column
layout module, but it is designed for flowing text across columns of equal
The best bet for pure CSS multi-column layouts that I see on the horizon is
particularly ironic twist, these properties would let you set the column blocks
to behave as table cells for the purposes of layout. Design techniques would
come full circle while still preserving the content/style division of CSS layout.
Article Sponsor
The contents of this webpage are copyright © 1998- 2003 SitePoint Pty. Ltd. All Rights Reserved.
Content Management System by Editize - Web Design & Development by sitepoint.com.au - Expired
Domain Names