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.

How to float an element<br />

Let’s step through an example of how you get<br />

an element to float, and then we’ll look at what<br />

it does to the flow of the page when you do.<br />

<strong>First</strong>, give it an identity<br />

Let’s take one of these paragraphs and give<br />

it an id. We’d like to call it the “amazing<br />

floating paragraph”, but we’ll just call it<br />

“amazing” for short.<br />

Now give it a width<br />

A requirement for any floating element is that it<br />

have a width. We’ll make this paragraph 200 pixels<br />

wide. Here’s the rule:<br />

#amazing {<br />

width: 200px;<br />

}<br />

Now the paragraph is 200 pixels<br />

wide, and the inline content<br />

contained in it has adjusted to that<br />

width. Keep in mind, the paragraph<br />

is a block element, so no elements are<br />

going to move up beside it because all<br />

block elements have linebreaks before<br />

and after them.<br />

h1<br />

h2<br />

h2<br />

p<br />

p<br />

p<br />

text<br />

p id=“amazing”<br />

h1<br />

h2<br />

h2<br />

p<br />

p<br />

p<br />

text<br />

text<br />

span em span em<br />

layout and positioning<br />

text<br />

text<br />

text<br />

text<br />

img img img img<br />

text<br />

p id=“amazing”<br />

text<br />

text<br />

text<br />

text<br />

text<br />

span em span em<br />

text<br />

text<br />

text<br />

img img img img<br />

you are here 495

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

Saved successfully!

Ooh no, something went wrong!