Dreamweaver 8[c] The Missing Manual

6.7. Style Properties

Cascading Style Sheets are a powerful and complex technology, providing many more formatting options than HTML alone. In fact, Dreamweaver lets you set 67 different CSS properties using the Rule Definition window. The following pages cover each of the eight Rule Definition categories and the properties available from each. (If you'd prefer an online reference, don't miss the built-in CSS reference available from the Window Reference command; its described more completely on Section 9.6.)


Note: As noted earlier, not all Web browsers can display the many different formatting options available through Cascading Style Sheets. Dreamweaver, in its zeal to give you access to as many options as possible, actually lets you set properties that don't work in many browsers, or that work differently in different browsers.There's some hope, however. Here are two sites whose charts detail which CSS properties work on which browsers:www.westciv.com/style_master/academy/browser_support/and http://macedition.com/cb/resources/abridgedcsssupport.html.

6.7.1. Type Properties

As the name implies, the Type category of the Rule Definition window lets you set formatting options that affect text (see Figure 6-17). Here are the settings you can adjust:

FREQUENTLY ASKED QUESTION

Pixels, Points, Picas, Oh My

When it comes to font size units, I never know which one to pick; which one should I use?

Specifying sizes, whether it's the size of a font on the page, or the width and height of a sidebar, is a common task when creating CSS styles. You'll notice that CSS lets you choose from a wide range of measuring systemseverything from the screen-dependent pixel to picas, points, and more. Most of these aren't relevant to designing pages that display on a computer screen. After all, a monitor doesn't really understand the concept of an incheven if your display is set to 72 dots per inch, 72 dots may occupy a half inch, an inch, or more depending on the screen's resolution (which you can change from 800 x 600 to 1600 x 1200 on the same monitor). The same goes for centimeters and millimeters. The bottom line? Skip 'em.

In general, stick to pixels, ems, and percentages. Pixel values are useful for dictating exact sizes on the screen, whereas ems and percentages are relative measurements. An em is a relative measurement based on the default text size of the browser viewing the page. Percentages are also a relative measurement and come in handy when your design needs to accommodate different sized monitors ; for example, say you wanted a particular paragraph to always fill up half the screen, no matter how wide the Web browser window. Setting the width of that paragraph to 50 percent ensures that the paragraph resizes to fit exactly 50 percent of any browser window. This type of arrangement is useful for "liquid layouts," like those discussed in the next chapter on Section 7.3.6.

Points and picas (two types of measurement used in typography and printed material) can also come in handy when you want your design to look just as good when it comes out of a laser printer. A point, in the computer world, is 1/72 of an inch; a pica is 12 points. You're probably used to "points" if you've used a word processor or a page-layout program; 12 points is a common size for type in these kinds of applications. Picas and points also are used by your inkjet or laser printer, which would be at a loss to understand what you meant by 12 pixels. Use this type of measurement when defining styles in an external style sheet that you attach using Dreamweaver's "printer media" option (see Section 6.3). By doing so, you can create "printer-friendly" font styles that produce elegant looking copies from your printer.

6.7.2. Background Properties

While you're probably familiar with changing the background colors of Web pages, tables, and table cells , Cascading Style Sheets provide even more options for adding colors and images to the backgrounds of your styles (see Figure 6-20).

Figure 6-20. The CSS Background category lets you specify a background color for a style; it also lets you control the placement of background images. Dreamweaver can't preview the "Fixed" option for the Attachment property (Section 6.7.2.3), so to get an accurate view of what this property does, you need to preview it in a Web browser.

6.7.2.1. Background color

Any object can have a background color: a single word, a paragraph, or the Web page itself. Using this color box, you can redefine the <td> (table cell) tag, for example, using a light-blue background color (every table cell on the page gets filled with that light-blue color), or create a " reversed -out" text effect for headlines, by setting a dark background color behind a light text color; the background color looks like a box out of which jumps the light-colored headline.

6.7.2.2. Background image

Add a background image to the style by clicking the Browse button and selecting an image from your site. You can also type an absolute URL, starting with http:// , to use an image off the Web.

To fill your entire page background with some repeating graphic, you could either redefine the <body> tag using this property, or create a class style with a Background Image property and apply it to the <body> tag as described on Section 6.3.2.

You can even control how the image tiles (repeats) and where it's placed on the page (see the following sections). Further more, you can add background images to any individual element on your page: paragraphs, tables, layers , and so on.

Background images appear above any background color, so you can (and often will) combine the two. For example you may want to position an interesting graphic on top of a colorful background.


Tip: One common byte-saving technique is to create an image that looks like a button and then use it for the background image of navigation links on a page. The links themselves include text"Home," "About Us," and so onbut the background of each link looks like a graphical button. The main benefit of this technique is that you don't need to create separate graphics for each button.
6.7.2.3. Background repeat

Background imagesas the background of either a page (Section 1.3.3) or of a table (Section 7.7.3)normally fill the available space by tiling (that is, repeating over and over again) across and down. A small image of a carrot added to the background of a page, for example, appears as a field of carrotsone next to another, row after row.

But with CSS, you can control how the background image repeats. You can select from the following options:

6.7.2.4. Background attachment

By default, the background image on a page scrolls with the rest of the page, so that as you scroll to read a long Web page, the image scrolls along with the text.

But using CSS, you can lock the image in place by choosing "fixed" from the Attachment menu. For example, say you added your company's logo to the background of a page and set the Repeat property (described above) to "no-repeat." The logo now appears only once in the upper-left corner of the page. If you use the "fixed" option for this property, when a visitor scrolls the page, the logo remains fixed in the upper-left corner. (Choosing "scroll" from the Attachment menu means, of course, that the background image scrolls with the page.)


Note: Internet Explorer for Windows supports the "fixed" setting only when it's applied to the <body> tag.
6.7.2.5. Horizontal and vertical position

Using these controls, you can specify a position for the affected text or other Web page element. The Horizontal Position options are: "left," "center," and "right." You can also choose "(value)," type an exact number in the box, and then select a unit of measurement from the menu to the right. Similarly, the Vertical Position options include "top," "center," and "bottom," or you can enter a specific value.

These positioning options refer to the position of the styled object. For example, suppose you created a class style that included a background image with Horizontal and Vertical Position both set to center . Then you applied that class style to a paragraph. The background image would appear in the center of that paragraph , not in the center of the Web page (see Figure 6-21).

Figure 6-21. Background images aren't just for the body of a Web page. You can apply styles that include background images to any selection, even a paragraph of text. Here, a class style with a background image is set to "no-repeat" (the image won't tile) and to center horizontally and vertically. The style was applied to the body of the page, resulting in the graphic appearing smack dab in the middle of the window. Meanwhile, the same style was applied to a paragraph; this time, the image floats right in the middle of the paragraph.

Likewise, if you set the horizontal position of the image to 10 pixels and the vertical position to 20 pixels, the image would start 10 pixels from the left edge of the paragraph and 20 pixels from the top edge.

And if you wanted to place an image in the exact middle of the page, you'd choose "center" from both the Horizontal and Vertical Position menus , set the Repeat property to "no-repeat," and apply the style to the page's <body> tag (see Figure 6-21).

6.7.3. Block Properties

The Block Properties panel is a hodgepodge of CSS settings that affect how letters and words are displayed (see Figure 6-22).

Despite this category's name, these properties don't just apply to block-level elements(paragraphs, headlines, and so on). You can apply a style with these properties to even a single word or two. (The one exceptionis the Text Align property, which can apply only to paragraphs and other block-level elements.)

6.7.4. Box Properties

CSS lets you control the space that appears around any affected Web page element. You work with those properties in the Box category of the CSS Rule Definition window (see Figure6-23).

Figure 6-23. Top: In the CSS Box model, every style is composed of multiple boxes, one inside the other. Each box controls certain display properties of the style. For example, the outermost box of a style is called the margin. It controls the space between the border of the style and any other objects around the styled object, such as images, paragraphs, or tables.

Bottom: This dialog box controls the margins and padding around a styled object that uses the Box category. Its fields correspond to the measurements shown in the top diagram. For a discussion of the Box model from the World Wide Web Consortium, visit: www.w3.org/TR/CSS21/box.html.


Tip: You can also use the Margin properties to eliminate a margin entirely, if, for example, you don't like the space that browsers automatically insert between paragraphs. Type in the Top margin box and in the Bottom margin box to create a style with no top or bottom margins.
6.7.4.1. CSS Layout Box Model

Margins and padding are invisible. They also have similar effects: 5 pixels of left padding adds 5 pixels of space to the left edge of a style, just like with a 5-pixel left margin. Because you can't see padding or margins (just the empty space they make), it's often difficult to know if the gap between, say, the banner at the top of your page and the main area of content is caused by the style applied to the banner or the main area. You also can't always tell if any extra space is caused by a padding or margin setting. Dreamweaver 8 adds a helpful diagnostic tool that lets you see these invisible properties clearly.

When you select a <div> tag (see page303) that has margin or padding properties set, Dreamweaver draws a box around that div and adds slanting lines to indicate the space occupied by margins and padding (see Figure 6-24).

Figure 6-24. In addition to displaying the space occupied by margins and padding, the CSS Layout Box Model's visual aids indicate the vertical and horizontal center point of the <div> tag (circled in this figure).

Margins appear outside of padding and are represented by lines that slant downward from left to right; padding appears inside of the margin and is represented by lines that go upward from left to right. For example, in Figure 6-24, the area that contains the main story is enclosed in a <div> tag with an ID style named main applied to it. When that div is selected (see the tag selector in the lower-left corner of the figure), Dreamweaver highlights the margins and padding values that are defined in that ID style. As you can see, there's a considerable amount of margin on both the top and left edges, and a smaller amount of padding (20 pixels) applied to both the left and right edges.


Note: Dreamweaver also displays visual aids for margins and padding values around any element with a style that has its display property set to "block" (see Section 6.7.3) or that uses either "absolute" or "relative" positioning (these properties are described in Chapter 8 on Section 8.3.1).

If you find these visual aids confusing, you can turn them off via the Visual Aids menu in the document window (see Figure 6-24) or by choosing View Visual Aids Layout Box Model. These same steps turn the margin and padding visual aids back on.

6.7.5. Border Properties

Only a few elements can have borders in HTML: tables, images, and cells. With CSS, however, you can add a border to any object, from an image to a paragraph to a single exclamation point (see Figure 6-25).

Figure 6-25. Top: Add colorful and stylish borders to paragraphs, images, tables, and links with the CSS Border properties. Turning on only the bottom border for a paragraph is a great way to add a horizontal rule between paragraphs. While HTML's Horizontal Rule object also does this, only CSS lets you control the color.

Bottom: The eight different border styles provide interesting visual diversity to the otherwise plain border.

Even better, you can control each side of the border independently with its own width and color settings, or even turn off some parts of the border:


Note: You have to select a style from the pop-up menu to see the borders. If you leave this option blank or select "none," you won't see the borders even if you set the width and color.

6.7.6. List Properties

To exercise greater control over bulleted and numbered lists, use the CSS options on the List panel of the CSS Rule Definition window (see Figure 6-26).

Figure 6-26. Top: Take control of your bulleted and numbered lists using the CSS Rule Definition window's List panel. With Cascading Style Sheets, you can even supply your own graphic bullets.

Bottom: A bullet-crazed Web page, for illustration purposes. Parading down the screen, you can see "inside" bullets, "outside" bullets, and bullets made from graphics.

6.7.7. Positioning Properties

Cascading Style Sheets may be useful for formatting text and adding background colors and margins to objects, but this technology is also intended as a structural aid for laying out Web pages. You'll learn about these properties and how to set them on Section 8.3.1.

6.7.8. Extensions

The final category in the CSS Rule Definition window is listed last for a good reason: not all Web browsers support its properties properly:

Категории