How to Create CSS Liquid Layouts

CSS Tutorial

Nikki Freeman
Liquid Layouts are used to create clean CSS designs that can expand or contract depending upon the browser size. They are becoming standard for a lot of new website designs, and Web 2.0 highly recommends the CSS liquid layout technique.

Liquid layouts base the dimensions of the columns, header, footer and content areas on percentages. Of course there are some actual pixel sizes constrained depending on your design, but essentially, the width of the web design will be completely designed using percentages based on the browser size.

This CSS tutorial will explain how to create a simple CSS liquid layout. Once you've mastered the concepts of the liquid layout, you can start getting creative and apply it to any type of design your heat desires! Just keep in mind, that CSS liquid layouts are not meant for every type of design, there are places to use it, and places not to.

Before we begin, here are some examples of nice CSS liquid layout designs:

Clear Left Liquid Layout

Site Point Liquid Layout

Now, on to the CSS tutorial:

1. Decide on a basic layout based on the grid system. Use the 800px wide standard, and measure out the amount of space you want between columns (gutters), width of columns and the width of your content area.

2. Convert these standard measurements into percentages based on the pixel measurements. Here is an example of what one type of conversion might look like:

gutter 1- 24px 3%
column 1- 384px 48%
gutter 2- 24px 3%
column 2- 160px 20%
gutter 3- 24px 3%
column 3- 160px 20%
gutter 4- 24px 3%

total 800px 100%

3. When calculating your percentages in a CSS liquid layout, we are not basing them on an exact 800px width, we are basing them on the variable size of a browser the user might view the website in. So, make sure you leave some room within your calculations for errors that may occur. This means rounding one or two of your measurements down a percentage point. One way to do this is to have the percentage width of a gutter set to undefined. For this example, let's set Gutter 4 to the value of undefined.

4. Up until this point, we have been going over the process vicariously. Because, obviously, there is no value available to define what a "Gutter" is. So, to replace out gutters we will use the "Left-Margin" attribute instead.

5. Getting into the actual code, now we will make each of the columns described above into their own DIV tags.

Here is the CSS Code:

#column1 { float: left; width: 48%; margin-left: 3%; display: inline; }

#column2 { float: left; width: 20%; margin-left: 3%; }

#column3 { float: left; width: 20%; margin-left: 3%; }

You may have noticed that I added an attribute display: inline to the first column. This is to eliminate a bug that occurs in IE 5, 5.5, and 6. These browsers have some quirks when it comes to margins and floats, and sometimes will cause the column to slip down past the others. This fix should do the trick.

6. Adding Headers and Adding Footers to your CSS float Layout

Place the Header above the other Columns and make sure it is not set to float. The footer will be at the bottom of the header, columns, gutters and will have an attribute to "clear: both". This is so the Liquid Layout will stay above the footer, and the footer will be below the layout design. You HTML will look like this:

Your CSS Code will look like this:

#header { margin-bottom: 10px; }

#column1 { float: left; width: 48%; margin-left: 3%; display: inline; }

#column2 { float: left; width: 20%; margin-left: 3%; }

#column3 { float: left; width: 20%; margin-left: 3%; }

#footer { clear: both; }

7. This is pretty much it! You have created your first CSS Liquid Layout using the Box model. But, one thing to note, is that when you go to place text elements within these columns, you should apply margins to your H2, P, H1, etc. elements rather than the boxes. This will allow some space in between your column edges and the text you put within them. Good Luck with your layout, and don't forget to get creative! Just keep within the standards too... :)

Published by Nikki Freeman

Freelance Writer, Graphic Designer, Web Designer. My first passion was writing, my second Art, my third singing/songwriting/music/my guitar, fourth technology. Put them all together and somehow they manage t...  View profile

  • CSS Liquid Layouts are becoming standard for Web 2.0
  • CSS Liquid Layouts base the size of the columns as percentages relative to the browser size
  • A CSS Liquid Layout Floats the Columns

8 Comments

Post a Comment
  • Cristian Dorobantescu12/6/2010

    You can have a look as well at <a href="http://www.extendstudio.com/product/tableless-css-layouts-for-dreamweaver.html">Flexi CSS Layouts</a> - a Dreamweaver Extension that help you create Css layouts in Dreamweaver without coding.

  • Sudhir12/19/2008

    Copy paste from max designs article

  • Russ Weakley2/23/2008

    Looks like this was basically taken from my article over on Max Design:
    http://www.maxdesign.com.au/presentation/liquid/

    Not cool.

  • Gavin D11/22/2007

    Desert lion

    Use the property
    overflow:hidden;

    that way long links and images will not break your layout when the user agent is resized.

  • symbiote9/7/2007

    It is a great tutorial ..
    but does it work on IE 6.0 ??

  • thuy8/28/2007

    You should have a sample for this tutorial, like a download of the finsih codes.

  • Desert Lion7/24/2007

    When I try to do this, I got an error message like this :
    "Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.

    Affects: Internet Explorer 6.0
    Likelihood: Likely"
    What should I do with that??? Thank You

  • Nikki Freeman12/28/2006

    Thanks Nick! Hope it helps :)

Displaying Comments

To comment, please sign in to your Yahoo! account, or sign up for a new account.