Home > Articles

Cascading Style Sheets

  • Print
  • + Share This
This chapter is from the book

Style Properties

Dreamweaver MX 2004 provides a handy interface for setting CSS properties on your styles, dividing the properties into several menus of related options. These menus can set all the most useful style properties, although not all CSS properties are covered. Additional CSS properties can be set by editing the CSS file in code view, as described later in this chapter.

The rest of this section describes each option menu in turn and the associated style properties. To learn more about each CSS property, you can consult the O'Reilly CSS Reference accessible through Help, Reference. Another good source of CSS knowledge is Teach Yourself CSS in 24 Hours, published by Sams.


Dreamweaver MX 2004 does not give the name of CSS properties in the option menus; for example, it has a box for Size and doesn't mention the CSS property name font-size anywhere. This makes Dreamweaver MX 2004 somewhat easy to use, but it can make it difficult to look up CSS properties in other references. For this reason, style options in this chapter will be followed by the name of the CSS property in parentheses.

Text Options

The text options control the appearance of the selected text. Many of these options are very similar to the <font> tag in HTML, although CSS styles offer you greater control than allowed in HTML styles. The complete list of text options, and the effects produced by each, are shown in Table 10.2.

Table 10.2 CSS Text Properties

Option (CSS Name)


Font (font-family)

Sets the font face choice(s) and default font family.

Size (font-size)

Sets the size of the text to absolute or relative sizes.

Weight (font-weight)

Sets the text to bold, light, bolder, lighter, or a numeric value (100 is lightest, 500 is normal, and 900 is darkest).

Style (font-style)

Sets the font to italic or oblique.

Variant (font-variant)

Sets the text to small capital letters instead of lowercase letters.

Line Height (line-height)

Sets the line spacing; a value of 2 ems equals double-spaced text.

Case (text-transforms)

Changes the case of the text using CSS.

Decoration (text-decoration)

Adds special effects to the text, such as underlines, overlines, strikethroughs, or blinking text.

Color (color)

Sets the (foreground) color of the text.

One concept unique to CSS that does not appear in HTML is that of generic font families. When you specify a font-family value, you are actually listing several fonts. If the user's computer doesn't have the first font, the browser will pick subsequent fonts from the list until it finds a match. Your final font-family value should be a generic font that is similar to the specific fonts you're attempting to use.

The generic fonts are sans-serif, serif, monospace, fantasy, and cursive. Each browser has a default value for each generic family, and it will use that if no other font from your list is found. For example, if you set a font-family value of Georgia, serif and the user's computer doesn't have the Georgia font installed, the browser will display the generic serif font (which, for most browsers, is Times New Roman).

Background Options

In HTML, you can set the background for the whole page or for individual table cells. With CSS styles, you can set a background for any part of the page and a background image as well. The background options are summarized in Table 10.3.

Table 10.3 CSS Background Properties

Option (CSS Name)


Background Color (background-color)

Sets the background color.

Background Image (background-image)

Selects a background image, which (by default) is tiled.

Repeat (background-repeat)

Determines if the background image tiles (repeat), repeats horizontally (repeat-x), repeats vertically (repeat-y), or doesn't tile at all (no-repeat).

Attachment (background-attachment)

Determines if the background image scrolls or remains fixed when the page scrolls.

Horizontal (background-position)

Determines the initial placement of the background image; can be left, middle, or right, a measurement, or a percentage.

Vertical (background-position)

Determines the initial placement of the background image; can be top, middle, or bottom, a measurement, or a percentage.

The Repeat, Attachment, Horizontal Position, and Vertical Position options apply only if there's a chosen background image. Background images may not load if the user has image loading turned off, so you'll want to choose a background color that is similar to your background image, if possible.


When you set the text color, it's a good idea to also set the background color and make sure that there is good contrast between the foreground and background. This will help users with visual impairments read your page more easily. Also, if you set the text color alone and not the background, you could cause problems for your users who set their browsers to different default colors. For example, setting the text to black but not the background to white will make your words invisible to users with white-on-black default settings, a common combination for people with low vision.

Block Options

The block options are CSS properties that affect the display of a block of text. These options are shown in Table 10.4.

Table 10.4 CSS Block Properties

Option (CSS Name)


Word Spacing (word-spacing)

Increases or (for negative values) decreases the spacing between words.

Letter Spacing (letter-spacing)

Increases or (for negative values) decreases the spacing between letters.

Vertical Alignment (vertical-align)

Determines the vertical placement relative to the text baseline.

Text Align (text-align)

Determines the horizontal alignment; justify aligns the text on both right and left.

Text Indent (text-indent)

Indents the first line of the text by a given measurement or percentage.

Whitespace (white-space)

Determines whether whitespace will be ignored (normal, the default), treated as preformatted text (pre), or displayed without line wrapping (nowrap).

Display (display)

Sets a block so that it's not displayed (none) or is displayed as another type of markup element.

The display property can be used to make an element invisible; this can be useful for text you want to show to users who aren't using a CSS-enabled browser, because the display property will be ignored along with all other CSS. Just don't use it to show a message such as "Upgrade your browser, loser!" because that's plain rude.


You might assume that you can use the Text Align option to center tables and other block elements; unfortunately, that's an incorrect—but natural—assumption. The CSS text-align property aligns only inline content such as text; if you need to center a block element such as a <table>, set the margins of the left and right sides to the value auto. Margin is one of the box options.

Box Options

CSS browsers display all HTML elements as a series of nested boxes. The box options control the characteristics of those boxes, as shown in Table 10.5.

Table 10.5 CSS Box Properties

Option (CSS Name)


Width (width)

Sets the width of the display box to a measurement or a percentage.

Height (height)

Sets the height of the display box to a measurement or percentage.

Float (float)

Makes the box float to the right or left, and subsequent content flows around it on the other side.

Clear (clear)

Stops content from flowing around boxes that float on the right or left.

Padding (padding)

Sets the padding of the box to a measurement or percentage; can be set separately on each side.

Margin (margin)

Sets the margin of the box to a measurement or percentage; can be set separately on each side.

An HTML element's CSS display box is like an onion; it is composed of a number of layers wrapped around each other. The outer layer is the margin; the margin is transparent, and the value of the margin specifies the minimum distance that box must be from another nearby box. Vertical margins will collapse, which means that only the largest value will be used between two boxes. This makes sense; it's like if Lois said, "Everyone has to stay three meters away from me," and Clark declared, "Everyone has to stay one meter away from me." They will use the larger limit of three meters, instead of adding them together and staying four meters from each other.

Within the margin is the border layer, which is set by the border options (covered in the next section). Within the border is the padding; the padding isn't transparent, but is set to the same background color (or image) as the element itself. The innermost part of the display box is the element content itself. The width and height properties set the content width, not the total of the content, the padding, the border, and the margin, or some combination thereof.

Border Options

The border options enable you to draw lines around CSS display boxes. Each box can have one border, but you can style each side of that box differently if you want. The border options are shown in Table 10.6.

Table 10.6 CSS Border Properties

Option (CSS Name)


Style (border-style)

Sets the type of line used to draw the border; can be set separately on each side.

Width (border-width)

Sets the width of the line used to draw the border as a measurement or percentage; can be set separately on each side.

Color (border-color)

Sets the color of the line used to draw the border; can be set separately on each side.

The lines drawing a border can be set to give a three-dimensional effect by the use of outset or inset or by using different colors on the top and left borders.

List Options

The list options shown in Table 10.7 affect only lists created with the HTML <ul> or <ol> tags, and they apply only to the <li> elements within those lists. These properties enable you to change the appearance of the marker before each list item, which is a bullet for unordered lists (<ul>) or a counter for ordered lists (<ol>).

Table 10.7 CSS List Properties

Option (CSS Name)


Type (list-style-type)

Determines the type of marker used before each item in the list; can be bullets (disc, circle, square) or counters (decimal, lower-roman, upper-roman, lower-alpha, upper-alpha).

Bullet Image (list-style-image)

Selects an image file (GIF, JPEG, or sometimes PNG) that replaces the list marker.

Position (list-style-position)

Determines whether the list marker is placed inside or outside of the margin of the list item.

Unfortunately, the CSS language does not have a way to specify the starting value for a list counter; for example, there's no way to start counting at six using CSS rules.

Positioning Options

The positioning options enable you to precisely lay out the Web page using CSS properties instead of HTML tables—in theory, at least. In practice, the CSS positioning properties tend to be irregularly supported, and it takes a lot of work and testing to make Web pages that work correctly in most browsers. In most cases, it's easier to use <table> markup for layout. The options for positioning CSS are shown in Table 10.8.

Table 10.8 CSS Positioning Properties

Option (CSS Name)


Type (position)

Chooses the positioning scheme used to place the box.

Width (width)

Sets the width of the display box to a measurement or a percentage.

Height (height)

Sets the height of the display box to a measurement or percentage.

Visibility (visibility)

Determines whether the box is shown; if not shown, the space for the box is still reserved in the layout.

Z-Index (z-index)

Determines the stacking order for boxes placed over each other; higher-numbered boxes are at the top of the stack.

Overflow (overflow)

Determines what should be done if the space required to display all the content exceeds the dimensions set by the height and width; excess content can flow out of the box (visible), be clipped (hidden), or be accessed via scrollbars (scroll).

Placement (left, right, top, bottom)

Places the box as an offset from its content box, as determined by the chosen positioning scheme.

Clip (clip)

Sets a mask within the box that hides displayed content outside of the clipping box.

To use CSS positioning, first you must decide on the positioning scheme to be used: static, relative, absolute, or fixed. The scheme determines the context box for the positioned element, and its final position is located relative to that context box.

Static positioning is simply the normal way pages are laid out without CSS positioning; it's the default value. Relative positioning calculates the static position and then applies offsets relative to that position. Absolute positions are calculated based on the location within the browser window or within any parent element that's been positioned. Fixed positioning is like absolute positioning, except that the fixed content never scrolls when the page scrolls; it remains fixed in position.

Offsets move the positioned box relative to its context box, with positive offsets moving toward the center of the box and negative toward the outside. These offsets are determined by the values given to the top, right, bottom, and left properties.

Extensions and Filters

The extensions and filters options constitute a catch-all category; it's where Dreamweaver MX 2004 places miscellaneous CSS properties. These properties are shown in Table 10.9.

Table 10.9 CSS Extensions and Filters

Option (CSS Name)


Page Break Before (page-break-before)

Tells the printer to start on a new page before printing this element.

Page Break After (page-break-after)

Tells the printer to start on a new page after printing this element.

Cursor (cursor)

Change the pointer when the mouse is over this element.

Filter (filter)

Apply a special effect filter; nonstandard CSS.

The filters are poorly supported—and because they're not part of the CSS specifications, that's to be expected. You shouldn't rely on them, although the majority of browsers will simply ignore those properties.

Shorthand Properties in CSS

If you open up the Preferences dialogue box in Dreamweaver MX 2004 and look at the CSS preferences, you'll find they deal exclusively with something called shorthand properties, as shown in Figure 10.6.

Figure 10.6Figure 10.6 CSS preferences in Dreamweaver MX 2004 control the use of shorthand properties.

A shorthand property is a simple way of writing several properties at once. For example, consider the following rules:

background-color: blue;
background-image: url("mybg.gif");
background-repeat: repeat-y;
background-position: top left;

Those rules can be written more compactly using the background shortcut property:

background: blue url("mybg.gif") repeat-y top left;

The CSS Preferences panel allows you to choose whether Dreamweaver MX 2004 will write certain properties using this shorthand notation or will write out every rule. The list of shorthand properties is shown in Table 10.10.

Table 10.10 CSS Shorthand Properties

Shorthand Property

Properties Set


font-style, font-variant, font-weight, font-size, line-height, font-family


background-color, background-image, background-repeat, background-attachment, background-position


margin-top, margin-right, margin-bottom, margin-left


padding-top, padding-right, padding-bottom, padding-left


border-style, border-width, border-color


list-style-type, list-style-image, list-style-position

If you set Dreamweaver to use shorthand properties, keep in mind that setting a shorthand property has two effects: It sets all associated properties to their default values, and then it sets the listed values. So if you use the shorthand property font with a value of 8px Verdana, remember that you've also just set the font-weight to normal (the default value for that property).

Dreamweaver MX 2004 writes the properties for you most of the time, so there's no great value in turning on the shorthand properties in CSS preferences.

CSS Validation

Dreamweaver MX 2004 enables you to check your HTML code for validity and conformance to accessibility standards, but unfortunately, it does not provide the same capability for style sheets.

Instead, you can use the W3C's CSS validator, which runs via the Web, to check your CSS for code mistakes or omissions. You can verify your style sheet by going to http://jigsaw.w3.org/css-validator/. Sample output from the CSS validator is shown in Figure 10.7.

Figure 10.7Figure 10.7 The W3C's CSS validator can spot code problems and provide helpful warnings.

  • + Share This
  • 🔖 Save To Your Account