04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ox width and height fine points<br />

Q: If I don’t set the width of an<br />

element, then where does the width come<br />

from?<br />

A: The default width for a block element<br />

is “auto”, which means that it will expand to<br />

fill whatever space is available. If you think<br />

about any of the Web pages we’ve been<br />

building, each block element can expand to<br />

the entire width of the browser, and that’s<br />

exactly what it does. Now, hold this thought,<br />

because we’re going to go into this in detail<br />

in the next chapter. Just remember that<br />

“auto” allows the content to fill whatever<br />

space is available (after taking padding,<br />

border, and margin into account).<br />

Sharpen your pencil<br />

446 Chapter 11<br />

there are no<br />

Dumb Questions<br />

Q: What if I don’t have any margin,<br />

padding, or borders?<br />

A: Then your content gets to use the<br />

entire width of the box. If the width of the<br />

content area is 300 pixels, and you have no<br />

padding, border, or margin, then the width of<br />

the entire box would also be 300 pixels.<br />

Q: What are the different ways I can<br />

specify widths?<br />

A: You can specify an actual size<br />

– usually in pixels – or you can specify a<br />

percentage. If you use a percentage, then<br />

the width is calculated as a percentage<br />

of the width of container the element is in<br />

Here’s a box that has all the widths labelled. What is the width of the entire box?<br />

30 pixels<br />

2 pixels<br />

5 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 />

200 pixels<br />

10 pixels<br />

2 pixels<br />

20 pixels<br />

(which could be the , a , etc.).<br />

Q: What about the height?<br />

A: In general, the height of an element<br />

is left at the default, which is auto, and the<br />

browser expands the content area vertically<br />

so all of the content is visible. Take a look<br />

at the elixirs section after we set the width<br />

to 200 pixels and you’ll see the got a<br />

lot taller.<br />

You can explicitly set a height, but you<br />

risk cutting off the bottom of your content<br />

if your height isn’t big enough to contain<br />

it. In general, leave your element heights<br />

unspecified so they default to auto. We’re<br />

going to talk about this more in the next<br />

chapter as well.<br />

Your answer here

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

Saved successfully!

Ooh no, something went wrong!