CIS86 2007 Fall Leaves Logo
CIS86 2007 Basic CSS (Cascading Style Sheets)

Cascading Style Sheets (CSS) is the W3C standard for the visual presentation of Web pages. The basic idea is that CSS provides a mechanism to specify the appearance, position, and behavior of all elements on an HTML page. Furthermore, these definitions can be selectively applied to elements in a group of pages, allowing you to change the appearance of all those elements in a single place -- the style sheet. This also has the effect of reducing the size of your HTML pages, since you’re able to drop a lot of redundant markup. In the olden days, page layouts were created by forcing elements into cells of tables, usually nested in intricate ways. Table-based layouts add a large amount of markup HTML to your pages, and can easily obscure the underlying structure of the page. We won't be using tables for layout in this class!

If you want to explore what is possible with style sheets, check out the CSS Zen Garden, where there are dozens of pages with the exact same content but different style sheets. You will be amazed at the variety!

Three Ways to Apply Styles:

The Cascade part of CSS is the mechanism by which conflicting style directives are sorted out. This can be a most complex subject, but the gist of it is that usually the definition that takes precedence is the closest definition to the place in the source file where it is being used.

Here are four things you will find in CSS files or specifications. All declaration blocks can span multiple lines.

  1. Comments, as delimited by /* and */. These can be multi-line.
  2. HTML tags, followed by a declaration block.
  3. Class names (a dot followed by a label), followed by a declaration block.
  4. IDs (a '#' followed by a label), followed by a declaration block.

Structure of Style Rules

For more information about CSS properties, see the QuickProject textbook starting on page 106.

The Box Model

Many elements in HTML create block-level elements -- their presence defines a box. Anything that is a box can be styled with CSS. Boxes have specific properties relating to the rectangular box: borders, margins, padding. For cases where there isn't a box defined by existing HTML elements, you can create boxes in CSS using the DIV and SPAN tags. Spans are used where you want to apply styling to a relatively small element in a single place, such as turning the text color to green for a phrase. A DIV defines a box with no attributes initially, and you apply styling to the contents of the DIV box.

The Box Model

Normally, when you specify a width for a component, this does not include padding or borders. Some versions of Internet Explorer instead interpret the width as being the combination of the content, the padding, and the border.

Arcane Rules about Structure of Style Rules

Resolving Conflicts in Style Declarations (the Cascade):

Since style directives can be applied in many ways in a single file, CSS uses the cascade to resolve any conflicts between style definitions.

CIS86 2007 HomeLinksContact DFF • Site by Monolith Design