CSS layout I

Derek Bridge

Department of Computer Science,
University College Cork

CSS layout I

Aims:

Single column layout - centred

Single column layout - centred - fixed-width

Single column layout - centred - elastic

Single column layout - centred - liquid

Multi-column layout

Floating an image

Two-column layout - fixed-width

A page might have a header, navigation menu, main content and footer. The menu might be alongside the main content.

Two-column layout - fixed-width

Here's the CSS assuming nav comes before #main:

nav
{
    float: left;
    width: 152px;
}

#main
{
    margin-left: 152px;
}

footer
{
    clear: both;
}

You can increase #main's left margin to give a gap between the two columns.

Two-column layout - centred - fixed-width

Three-column layout - centred - fixed-width

A page might have a header, a navigation menu, main content, an aside and footer. The navigation menu might be alongside the main content. The aside may be a sidebar along the other side of the main content.

Three-column layout - centred - fixed-width

Assuming nav, then #main, then aside is the logical order

#wrapper
{
    margin-left: auto;
    margin-right: auto;
    width: 760px;
}

nav
{
    float: left;
    width: 152px;
}

#main
{
    float: left;
    width: 418px;
}

aside
{
    margin-left: 570px;
}

footer
{
    clear: both;
}