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.

frozen layouts<br />

A frozen test drive<br />

Go ahead and add this rule to the bottom of<br />

“starbuzz.css”, and then reload “index.html”. Now<br />

you can see why we call it a frozen layout. It doesn’t<br />

move when the browser is resized.<br />

Now the “allcontent” is 800 pixels in width, no matter<br />

how you resize the browser. And, because all the other s<br />

are inside “allcontent”, they will also fit into the 800 pixel<br />

space as well. So, the page is basically frozen to 800 pixels.<br />

518 Chapter 12<br />

What’s the state between liquid<br />

and frozen? Jello, of course!<br />

The frozen layout has some benefits, but it also just plain<br />

looks bad when you widen the browser. But we’ve got a fix,<br />

and it’s a common design you’ll see on the Web. This design<br />

is between frozen and liquid, and it has a name to match:<br />

Jello. Jello layouts lock down the width of the content area in<br />

the page, but center it in the browser. It’s actually easier to<br />

change the layout to a jello layout and let you play <strong>with</strong> it,<br />

than to explain how it behaves, so let’s just do it:<br />

#allcontent {<br />

width: 800px;<br />

padding-top: 5px;<br />

padding-bottom: 5px;<br />

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

margin-left: auto;<br />

margin-right: auto;<br />

}<br />

This certainly solves the problem of the sidebar<br />

expanding and it looks pretty nice. It is a little<br />

strange when the browser is very wide, though,<br />

because of all the empty space on the right side.<br />

But, we’re not done yet; we’ve got a<br />

little room for improvement.<br />

Rather than having fixed left and right<br />

margins on the “allcontent” , we’re<br />

setting the margins to “auto”.<br />

If you remember, when we talked about giving a content area a width of “auto”, the<br />

browser expanded the content area as much as it needed to. With “auto” margins,<br />

the browser figures out what the correct margins are, but also makes sure the left<br />

and right margins are the same, so that the content is centered.

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

Saved successfully!

Ooh no, something went wrong!