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.

Well then how do we<br />

specify the width of the<br />

entire element?<br />

You don’t. You specify the width of the content area,<br />

the padding, the border, and the margin. All of that<br />

added together is the width of the entire element.<br />

Say you set the content area width to be 300 pixels using the width property<br />

in a <strong>CSS</strong> rule.<br />

And let’s say you’ve set the margins to 20 pixels, the padding to 10 pixels, and you<br />

have a 1 pixel border. What’s the width of your element’s box? Well, it’s the width of<br />

the content area added to the width of the left and right margins, the left and right<br />

padding, and the left and right border width. Let’ see how to calculate that...<br />

20 pixels<br />

1 pixel<br />

10 pixels<br />

20 + 1 + 10<br />

31<br />

(1) The content area is 300 pixels.<br />

300 pixels<br />

Our guarantee: at the lounge, we’re<br />

committed to providing you, our guest,<br />

<strong>with</strong> an exceptional experience every<br />

time you visit. Whether you’re just<br />

stopping by to check in on email over<br />

an elixir, or are here for an out-ofthe-ordinary<br />

dinner, you’ll find our<br />

knowledgeable service staff pay attention<br />

to every detail. If you’re not fully satisfied<br />

have a Blueberry Bliss Elixir on us.<br />

300<br />

31 + 31 = 62<br />

10 pixels<br />

1 pixel<br />

20 pixels<br />

10 + 1 + 20<br />

31<br />

divs and spans<br />

(2) Figure out how much is taken up by<br />

the margins, padding, and border.<br />

(3) It looks like 62 pixels are taken up, so<br />

add that to the content area’s width of<br />

300 pixels, and we have 300 + 62 = 362<br />

pixels for the entire box.<br />

you are here 445

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

Saved successfully!

Ooh no, something went wrong!