22.04.2013 Views

HTML, XHTML & CSS

HTML, XHTML & CSS

HTML, XHTML & 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.

Chapter 10: Using Cascading Style Sheets<br />

You’ll note that we also set the line-height at 0.2em. This ensures that menu<br />

line entries are compact, without too much white space between individual<br />

elements.<br />

Note that several properties in the declaration, called shorthand properties,<br />

take multiple values, such as margin and padding. Shorthand properties collect<br />

values from multiple related <strong>CSS</strong> properties (such as margin-height,<br />

margin-width, and so forth). See our online materials for a complete list.<br />

Those values correspond to settings for the top, right, bottom, and left edges<br />

of the navbar’s box. margin creates an empty zone around the box, and<br />

padding defines the space between the edges or borders of the box and the<br />

content inside the box. Here are the rules that explain how to associate values<br />

with properties that deal with margins, borders, padding, and so forth:<br />

✓ If all the sides have the same value, a single value works.<br />

✓ If any side is different from the others, every side needs a separate value.<br />

It’s okay to set some or all of these values to 0 (zero) as you see fit; this<br />

can often help to ensure that pages display consistently across a wider<br />

range of browsers (and browser versions).<br />

To remember what’s what, think of the edges of an element box in clockwise<br />

order, starting with the top edge: top, right, bottom, and then left.<br />

Notice that we define margins and padding using px (pixels) rather than pt<br />

(points) or em (default character m’s width) as our unit of measure. This is<br />

a deliberate departure from best practices that we recommend elsewhere in<br />

this book (Chapter 11). That’s because margins and padding usually involve<br />

small increments or values and because those things relate very strongly to<br />

individual actual displays within specific browsers. Experiment with these<br />

values to get them just right, and be sure to check them on as many different<br />

browsers and platforms as you can to ensure that visitors to your Web site<br />

see what you intended.<br />

Positioning<br />

<strong>CSS</strong> provides several ways to specify exactly where an element should<br />

appear on a page. These controls use various kinds of positioning based on<br />

the relationships between an element’s box and its parent element’s box<br />

to help page designers put page elements where they want them to go. The<br />

kinds of properties involved are discussed in the following sections.<br />

Location<br />

You can control the horizontal and vertical locations of an image. However,<br />

when you use absolute positioning with any page element, you specify<br />

exactly where that element must sit, relative to the upper-left corner of the<br />

151

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

Saved successfully!

Ooh no, something went wrong!