Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Dreamweaver Developer Center /

Understanding cascading style sheets

by Jon Michael Varese

Jon Michael Varese
  • www.jmvarese.com

Modified

17 May 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
CSS design Dreamweaver CS5 website

Requirements

User level

All

Required products

  • Dreamweaver CS5 (Download trial)

Note: This article is repurposed from the Dreamweaver CS5 help system.

About cascading style sheets

Cascading style sheets CSS is a collection of formatting rules that control the appearance of content in a web page. Using CSS styles to format a page separates content from presentation. The content of your page—the HTML code—resides in the HTML file, and the CSS rules defining the presentation of the code reside in another file an external style sheet or in another part of the HTML document usually the head section. Separating content from presentation makes it much easier to maintain the appearance of your site from a central location because you don't need to update every property on every page whenever you want to make a change. Separating content from presentation also results in simpler and cleaner HTML code, which provides shorter browser loading times, and simplifies navigation for people with accessibility issues for example, those using screen readers.

CSS gives you great flexibility and control over the exact appearance of your page. With CSS you can control many text properties including specific fonts and font sizes; bold, italics, underlining, and text shadows; text color and background color; link color and link underlining; and much more. By using CSS to control your fonts, you can also ensure a more consistent treatment of your page layout and appearance in multiple browsers.

In addition to text formatting, you can use CSS to control the format and positioning of block-level elements in a web page. A block-level element is a standalone piece of content, usually separated by a new line in the HTML, and visually formatted as a block. For example, h1 tags, p tags, and div tags all produce block-level elements on a web page. You can set margins and borders for block-level elements, position them in a specific location, add background color to them, float text around them, and so on. Manipulating block-level elements is in essence the way you lay out pages with CSS.

For a tutorial on understanding CSS, watch the video Using CSS.

About CSS rules

A CSS formatting rule consists of two parts—the selector and the declaration or in most cases, a block of declarations. The selector is a term such as p, h1, a class name, or an id that identifies the formatted element, and the declaration block defines what the style properties are. In the following example, h1 is the selector, and everything that falls between the braces {} is the declaration block:

h1 { font-size: 16 pixels; font-family: Helvetica; font-weight:bold; }

An individual declaration consists of two parts, the property (such as font-family) and value (such as Helvetica). In the previous CSS rule, a particular style has been created for h1 tags: the text for all h1 tags linked to this style will be 16 pixels in size, Helvetica font, and bold.

The style (which comes from a rule, or a collection of rules) resides in a place separate from the actual text it’s formatting—usually in an external style sheet, or in the head portion of an HTML document. Thus, one rule for h1 tags can apply to many tags at once (and in the case of external style sheets, the rule can apply to many tags at once on many different pages). In this way, CSS provides extremely easy update capability. When you update a CSS rule in one place, the formatting of all the elements that use the defined style are automatically updated to the new style.

When you update a CSS rule in one place, the formatting of all the elements that use the defined style are automatically updated to the new style
Figure 1. When you update a CSS rule in one place, the formatting of all the elements that use the defined style are automatically updated to the new style

You can define the following types of styles in Dreamweaver:

  • Class styles let you apply style properties to any element or elements on the page.
  • HTML tag styles redefine the formatting for a particular tag, such as h1. When you create or change a CSS style for the h1 tag, all text formatted with the h1 tag is immediately updated.
  • Advanced styles redefine the formatting for a particular combination of elements, or for other selector forms as allowed by CSS for example, the selector td h2 applies whenever an h2 header appears inside a table cell. Advanced styles can also redefine the formatting for tags that contain a specific id attribute for example, the styles defined by #myStyle apply to all tags that contain the attribute-value pair id="myStyle" .

CSS rules can reside in the following locations:

  • External CSS style sheets: Collections of CSS rules stored in a separate, external CSS .css file not an HTML file. This file is linked to one or more pages in a website using a link or an @import rule in the head section of a document.
  • Internal or embedded CSS style sheets: Collections of CSS rules included in a style tag in the head portion of an HTML document.
  • Inline styles: Defined within specific instances of tags throughout an HTML document. Using Inline styles is not recommended.

Dreamweaver recognizes styles defined in existing documents as long as they conform to CSS style guidelines. Dreamweaver also renders most applied styles directly in Design view. Previewing the document in a browser window, however, gives you the most accurate "live" rendering of the page. Some CSS styles are rendered differently in Microsoft Internet Explorer, Netscape, Opera, Apple Safari, or other browsers, and some are not currently supported by any browser.

To display the O'Reilly CSS reference guide included with Dreamweaver, select Help > Reference and select O’Reilly CSS Reference from the pop‑up menu in the Reference panel.

About cascading styles

The term cascading refers to the way a browser ultimately displays styles for specific elements on a web page. Three different sources are responsible for the styles you see on a web page: the style sheet created by the author of the page, the user’s customized style selections if any , and the default styles of the browser itself. The previous topics describe creating styles for a web page as the author of both the web page and the style sheet attached to that page. But browsers also have their own default style sheets that dictate the rendering of web pages, and in addition to that, users can customize their browsers by making selections that adjust the display of web pages. The final appearance of a web page is the result of the rules of all three of these sources coming together or "cascading" to render the web page in an optimal way.

A common tag—the paragraph tag, or <p> tag—illustrates the concept. By default, browsers come with style sheets that define the font and font size for paragraph text that is, text that falls between <p> tags in the HTML code. In Internet Explorer, for example, all body text, including paragraph text, displays in Times New Roman, Medium font by default.

As the author of a web page, however, you can create a style sheet that overrides the browser's default style for paragraph font and font size. For example, you can create the following rule in your style sheet:

p { font-family: Arial; font-size: small; }

When a user loads the page, the paragraph font and font size settings set by you as the author override the default paragraph text settings of the browser.

Users can make selections to customize the browser display in an optimal way for their own use. In Internet Explorer, for example, the user can select View > Text Size > Largest to expand the page font to a more readable size if they think the font is too small. Ultimately (at least in this case), the user’s selection overrides both the default browser styles for paragraph font size and the paragraph styles created by the author of the web page.

Inheritance is another important part of the cascade. Properties for most elements on a web page are inherited—for example, paragraph tags inherit certain properties from body tags, bullet list tags inherit certain properties from paragraph tags, and so on. Thus, if you create the following rule in your style sheet:

body { font-family: Arial; font-style: italic; }

All paragraph text on your web page (as well as text that inherits properties from the paragraph tag) will be Arial and italic because the paragraph tag inherits these properties from the body tag. You can, however, become more specific with your rules, and create styles that override the standard formula for inheritance. For example, if you create the following rules in your style sheet:

body { font-family: Arial; font-style: italic; } p { font-family: Courier; font-style: normal; }

All body text will be Arial and italic except paragraph (and its inherited) text, which will display as Courier normal (non-italic). Technically, the paragraph tag first inherits the properties that are set for the body tag, but then ignores those properties because it has properties of its own defined. In other words, while page elements generally inherit properties from above, the direct application of a property to a tag always causes an override of the standard formula for inheritance.

The combination of all of the factors discussed above, plus other factors like CSS specificity (a system that gives different weight to particular kinds of CSS rules), and the order of CSS rules, ultimately create a complex cascade where items with higher priorities override properties that have lower priorities. For more information on the rules governing the cascade, inheritance, and specificity, visit www.w3.org/TR/CSS2/cascade.html.

More Like This

  • Responsive design with jQuery marquee
  • Understanding HTML5 semantics – Part 2: Document structure and global attributes
  • Using Modernizr to detect HTML5 and CSS3 browser support
  • Customizable starter design for jQuery Mobile
  • Customizable starter design for HTML5 video
  • Dreamweaver CS5 Missing Manual excerpts: Behaviors, site management, and templates
  • Using and customizing jQuery Mobile themes
  • Customizable starter design for multiscreen development
  • Marking up your site for easier redesign in five steps
  • Getting Started with CSS excerpts: Styling tables, backgrounds, and borders

Tutorials and samples

Tutorials

  • Understanding HTML5 semantics: Changed and absent elements
  • Mobile app with PhoneGap: Submitting to the Apple App Store
  • PhoneGap and Dreamweaver: Releasing on iOS
  • Mobile app with PhoneGap: Submitting to Android Market

Samples

  • Responsive design with jQuery marquee
  • Customizable starter design for jQuery Mobile
  • Customizable starter design for HTML5 video
  • Customizable starter design for multiscreen development

Dreamweaver user forum

More
04/23/2012 Resolution/Compatibility/liquid layout
04/20/2012 using local/testing server with cs5 inserting images look fine in the split screen but do not show
04/18/2012 Ap Div help
04/23/2012 Updating

Dreamweaver Cookbook

More
11/07/2011 Simple social networking share buttons
09/20/2011 Registration form that will generate email for registrant to validate
08/21/2011 Spry Accordion - Vertical Text - Auto Start on Page Load - Mouse Over Pause
08/17/2011 Using cfdump anywhere you like

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement