Holy Grail (web design)

The Holy Grail is a multi-column web page layout. It is commonly desired and implemented, although the ways in which it can be implemented with current technologies all have drawbacks.[1] Because of this, finding an optimal implementation has been likened to searching for the elusive Holy Grail.

The problem

Many web pages require a layout with multiple (often three) columns, with the main page content in one column (often the center), and supplementary content such as menus and advertisements in the other columns (sidebars). These columns commonly require separate backgrounds, with borders between them, and should appear to be the same height no matter which column has the tallest content. There are many obstacles to accomplishing this:

Common solutions

Tables

Before the widespread implementation of CSS, tables were commonly used to lay out pages. Sometimes the layout required several tables to be nested inside each other. Although placing the columns inside table cells easily achieves the desired appearance, using a table is semantically incorrect (although the "role" HTML attribute can be set to "presentation" to regain semantic context). There is also no way to control the order of the columns in the page source.

Divisions with display:table

It is possible to make columns equal height using the CSS display property.[3] This requires nested container divisions that are set to "display: table" and "display: table-row", and columns that are set to "display: table-cell". This is semantically correct, as only the display is affected. However, this will not work with older browsers such as Internet Explorer 7, and the method also lacks the ability to control the order of the source code.

Faux columns

This method uses a background image which provides the background colors and vertical borders of all three columns.[4] The content of each column is enclosed in a division, and positioned over its background using floats, negative margins, and relative positioning. The background is normally only a few pixels high, and is made to cover the page using the "repeat-y" attribute. This works fine for fixed-width layouts, and can be adapted for percentage-based variable-width pages, but cannot be used for fluid center pages.

JavaScript

In this method, after the page is loaded, a script measures the height of each of the columns, and sets the height of each column to the greater value. This will not work in browsers that do not support JavaScript, or have JavaScript disabled.

Fixed or absolute positioning

In this method, the corners of the column divisions are locked in a specific place on the page.[5] This may be acceptable or even desired, but does not solve the holy grail problem as it is a significantly different layout. The consequences of this method may include having content appearing below the columns (such as a footer) fixed at the screen bottom, blank space under the column content, and requiring scrollbars for each column to view all the content.

Nested divisions

Since a division will grow in height to contain its content, if this containing division is assigned a background, the background will be as tall as the content. This behavior is used to solve the problem by creating three divisions nested inside each other which provide the three backgrounds. These divisions are placed in their proper position using floats and relative positioning, and the three content divisions are placed inside the innermost background division, and positioned. The background divisions become as tall as the tallest content division. The drawbacks of this method include the three non-semantic divisions, and the difficulty of positioning the elements of this complex layout.[6]

Border color

A simpler version of the nested division method entails using a single container division. The background properties of this division provides the background of the center column, and the left and right borders, which are given widths equal to the side column widths, provide the background colors of the sidebars.The content of each column is positioned over its background using floats and relative positioning. This method still uses one non-semantic division, and makes it difficult to apply background images and borders to the sidebars.[7]

Bottom padding

By placing a large amount of padding at the bottom of the column container, the background will extend far below the column content. A corresponding negative margin will bring content below the columns back into its proper position. Positioning is simple in this method, as the container of a column's content also contains its background. A padding value of 32767px is the largest that will be recognized by all modern browsers. If the difference in column heights is greater than this, the background of the shorter column will not fully fill the column.[8]

CSS 3

The World Wide Web Consortium (W3C) has approached the layout issue through various proposals. As of September 2012, the flexible box module has reached candidate recommendation status,[9] and has support in all current desktop and many mobile browsers (Webkit-based browsers and some other mobile browsers require prefix filters).[10]

Work continues on the grid layout module, which is in last call working draft status (March 2014).[11] This module combines the Grid Positioning module (which has been abandoned[12]) and the (Grid) Template Layout module (which is currently not in development). There is limited browser support for the Grid Layout module,[13] but Web designers who wish to use the (apparently superseded) Template Layout syntax may add support to their pages through jQuery/javascript.[14] The Grid Layout and Regions modules are intended to be inter-compatible.[15]

When these standards become mature, and nonconforming browsers are no longer in common use, the Holy Grail problem will have become a non-issue.[16][17]

History

The first three-column flanking design that used pure CSS was developed by Rob Chandanais of BlueRobot[18] for the site wrongwaygoback.com[19] in 2001. At that point Neale Talbot was using JavaScript to determine the positioning of the right-hand column. Chandanais came up with an elegant solution for the positioning using pure CSS instead and soon after dubbed The Holy Grail by Eric Costello of Glish.com.[20]

See also

References