04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Liquid and Frozen Designs<br />

All the designs we’ve been playing <strong>with</strong> so far are called liquid layouts<br />

because they expand to fill whatever width we resize the browser<br />

to. These layouts are useful because, by expanding, they fill the<br />

space available and allow users to make good use of their screen<br />

space. Sometimes, however, it is more important to have your layout<br />

locked down so that when a user resizes the screen, your design still<br />

looks as it should. There are a couple of layouts that work like this,<br />

but let’s start <strong>with</strong> frozen layouts. Frozen layouts lock the elements<br />

down, frozen to the page, so they can’t move at all, and so we avoid<br />

a lot of issues that are caused by the window expanding. Let’s give a<br />

frozen layout a try.<br />

Going from your current page to a frozen page only requires one<br />

addition to your X<strong>HTML</strong>, and one new rule in your <strong>CSS</strong>.<br />

X<strong>HTML</strong> Changes<br />

In your X<strong>HTML</strong> you’re going to add a new element <strong>with</strong> the id<br />

“allcontent”. Like its name suggests, this is going to go around all the<br />

content in your page. So place the opening tag before the header<br />

and the closing tag below the footer .<br />

<strong>CSS</strong> Changes<br />

<br />

<br />

<br />

... rest of the X<strong>HTML</strong> goes here ...<br />

<br />

<br />

<br />

This closes the footer .<br />

Now we’re going to use this to constrain the size of<br />

all the elements and content in the “allcontent” to<br />

a fixed width of 800 pixels. Here’s the <strong>CSS</strong> rule to do that:<br />

#allcontent {<br />

width: 800px;<br />

padding-top: 5px;<br />

padding-bottom: 5px;<br />

background-color: #675c47;<br />

}<br />

Add a new <strong>with</strong> the id of “allcontent”<br />

around all the other elements in the .<br />

layout and positioning<br />

We’re going to set the width of “allcontent” to<br />

800 pixels. This will have the effect of constraining<br />

everything in it to fit <strong>with</strong>in 800 pixels.<br />

While we’re at it, since this is the first time<br />

we’re styling this , let’s add some padding<br />

and give it its own background color. You’ll see<br />

this helps to tie the whole page together.<br />

The outer “allcontent” is always 800 pixels, even when the browser is resized, so we’ve<br />

effectively frozen the to the page, along <strong>with</strong> everything inside it.<br />

you are here 517

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!