Home > Articles

Cascading Style Sheets

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.

NOTE

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)

Effect

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)

Effect

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.

TIP

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)

Effect

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.

TIP

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)

Effect

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)

Effect

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)

Effect

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)

Effect

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)

Effect

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

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

background

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

margin

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

padding

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

border

border-style, border-width, border-color

list-style

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.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020