Introducing Fluid Grid Layouts

In the previous post, Introducing Responsive Design we explored the basic concepts of a responsive website. We saw there were three major components; fluid grid layouts, CSS 3 media queries, and fluid images and media. In this second blog post we will look at the basics of fluid grid layouts and how they are used for designing responsive sites.

Grids solve the basic problem of alignment. A traditional web design defines a number of pixels across a page and then lays out the content to match the grid design. A quick Google search can reveal that there is no shortage of grid systems. The 960 pixel grid system is probably the most commonly used. Why? The number 960 makes for a lot of clean divisions utilizing a whole number when factoring column widths and margins; and technically fits nicely on a majority of screens.

The problem with pixels

Lets start by taking a look at a simple 960 pixel based HTML page with an inline CSS using the code shown below.

When run in full screen (1296x776) the HTML produces the following screenshot.

Now, lets make the window half the width of the screen (612x760) and we can see the design gets cut off as shown in the following screenshot.

When designing a responsive site every aspect of the site needs to be scaled appropriately. A quick review of CSS shows that in addition to pixels it also supports the following measurement types.

Unit type

Description

%

Percentage

in

Inch

cm

Centimeter

mm

Millimeter

em

1 em is equal to the current font size.

ex

1 ex is the x-height of a font (x-height is usually about half the font-size)

pt

Point (1 pt is the same as 1/72 inch)

pc

Pica (1 pc is the same as 12 points)

px

Pixels (a dot on the computer screen)

Moving to Responsive Design

A liquid or fluid grid goes beyond the traditional layout. Instead of designing a layout based on a rigid set of pixels a fluid grid is designed in terms of percentages (%). This means that a 50% width will always take up half the screen. This way when a layout is squeezed onto a small device or stretched across a huge screen, all of the elements in the layout will resize their widths in relation to each other.

Converting a pixel based layout to a proportional design isnt incredibly complicated but does require some math as shown in the following formula.

Target Context = Result

Here are the important parts of the formula that you should keep in mind.

Target

The size of the element in pixels.

Context

The size of the containing control in pixels.

Result

The proportional CSS rule as a percentage.

Lets see how this formula works by converting the simple page we created earlier. This page defines a container of 960 pixels. We want our resulting fluid grid to have the same proportion as the current design. So we will base our calculations on the 960 pixel baseline. So this makes the fluid formula very easy as shown below.

When run in full screen (1296x776) the HTML produces the following screenshot.

Now, lets make the window half the width of the screen (621x760) and we can see the following screenshot.

Dont forget

Fluid grids are an important part of responsive design. However, they can only take you so far. Often when the width of a browser becomes too narrow the design starts to break down. This is where media queries become important.

2 Column Design

Lets take a more complicated 2 column design that contains the following HTML.

When run in full screen (1296x776) the HTML produces the following screenshot.

Now, lets make the window half the width of the screen (631x471) and we can see the design becomes responsive as shown in the following screenshot.

Conclusion

In this second part we look at the basics of fluid grids within responsive design. We looked at how you can convert existing pixel based layouts to fluid grids. The code demonstrated is available for download from here.