CSS layout II

Derek Bridge

Department of Computer Science,
University College Cork

CSS layout I

Aims:

Liquid layouts

Three-column layout - centred - liquid

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.

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

#wrapper
{
    margin-left: auto;
    margin-right: auto;
    width: 76%;
}

nav
{
    float: left;
    width: 20%;
}

#main
{
    float: left;
    width: 55%;
}

aside
{
    margin-left: 75%;
}

footer
{
    clear: both;
}

Class exercise: Suppose viewport is 1000px wide. How wide will #wrapper, nav, #main and aside be?

Hybrid layouts

Hybrid layouts

Responsive web design

CSS3 Media queries

CSS3 Media queries

CSS3 Media queries

Mobile first

Example of mobile-first responsive web design

/* Styles that always apply, e.g.: */
body
{
    font-family: Verdana, Arial, Helvetica, sans-serif;
}

#wrapper 
{
    margin: 0 10px 0 10px;
    background-color: #fff;
}

nav ul
{
    list-style: none;
}

/* Styles that give a two-column layout when there is enough room, e.g.: */
@media screen and (min-width: 768px)
{
    #wrapper
    {
        margin-left: auto;
        margin-right: auto;
        width: 76%;	
    }
	
    nav
    {
        float: left;	
        width: 20%;
    }
	
    #main
    {
        margin-left: 20%;
    }

    aside
    {
        margin-left: 20%;
    }
	
    footer
    {
        clear: both;
    }
}

/* Styles that give a three-column layout when there is even more room, e.g.: */
@media screen and (min-width: 1024px)
{
    #main
    {
        float: left;
        width: 55%;
        margin-left: 0
    }
	    
    aside
    {
        margin-left: 75%;
    }      
}

Resolution breakpoints

320pxFor small screen devices, like phones, held in portrait mode
480pxFor small screen devices, like phones, held in landscape mode
600pxSmaller tables, like the Kindle (660×800) and Nook (600×1024), held in portrait mode
768pxTen-inch tablets like the iPad (768×1024) held in portrait mode
1024pxTablets like the iPad held in landscape mode, as well as some laptop, netbook and desktop displays
1200pxFor widescreen displays, primarily laptop and desktop browsers

From Responsive Web Design, Ethan Marcotte

And see resizeMyBrowser

How widely does it work?

A few final thoughts