Scintography Home
Previous ChapterTable of ContentsNext Chapter
Title Page

Chapter 6: Formatting Pages with STYLE


The Art of Scintography
Edition 3.0 © 2008 Aurora Isaac
www.scintography.com
    6.1   Unify Your Page Design
      If you have worked with HTML, you have probably discovered that changing the appearance of your site can be difficult. For example, if you want to change one of your page design colors, you may need to edit many files, changing the color in many places to get your new look. STYLE was invented to make this process easier. Using STYLE with HTML gives you the capability to:
  • Increase formatting control
  • Apply formatting to many pages
In a stylesheet you can specify design markup in one place and apply it to any page on your site. With a well designed site, you may only need to change your color in one place. If you have already worked with HTML, you will probably find STYLE easy to learn.
    6.2   A Style Sheet
      Style refers to the formatting language of Cascading Style Sheets. As the name implies, a number of style sheets may be used on a single document, cascading in a specified order. Each style sheet consists of a collection of style rules. A single style declaration has the format:

selector
{
  property1: value1;
  property2: value2;
  etc.
}

The selector selects elements of an HTML document, to which the style rules are applied. For example, if you want all text contained in bold tags to be red, the style rule is written:

B { color: red; }

Each time the <B>bold container</B> is encountered, the enclosed text will be bold and red. This formatting is a composite of the innate HTML attributes of the B tag, and the specifically defined properties of the B style.
      HTML generic tags do not impart any markup features to the enclosed source, but can be selected for style application. These are the <div></div> block tags and the <span></span> inline tags. The following text is formatted only with div and span tags. Without style rules applied, the formatting is simple. When the style is applied, the formatting becomes complex.
 

Without Style Applied
Style Demonstration
This section of text is formatted with minimal html markup using the generic div and span tags. Style rules are applied using the id and class attributes to select html elements.

 
With Style Applied
Style Demonstration
This section of text is formatted with minimal html markup using the generic div and span tags. Style rules are applied using the id and class attributes to select html elements.
 
Like HTML, STYLE is a simple text language that can be edited into a text file with any editor or word processor that can output a text only format. Separate STYLE source documents should be saved in files with the suffix name .css.
P {PROPERTY: VALUE;}

?

p {property: value;}
      STYLE is a case-insensitive language. Tagnames, properties, and most values may be in upper or lower case.
      Colors in STYLE, as in HTML, are specified by name or numerical code. Although several formats for specifying color codes are available, the most universal format is the #RRGGBB format. Use the Color Selector and Color Palette to find color names and numbers: Color Selector
      Dimensions in STYLE are generally specified with a number and a unit. Style offers a greater control over dimensions than HTML, offering the opportunity for more precise formatting. See the Appendix for a discussion of dimensions. Refer to the Unit Table for units used in STYLE: Style Units
     
! Browser Wars Alerts! Alerts will appear in the tutorials where significant variation in browser interpretation of code occurs.
    6.3   Style Selectors
 
   
Style 1
      Style selectors can be applied to HTML elements by tagname, or by the values of the id or class attributes. These are universal attributes that can be applied to any HTML element. Some pseudoclasses exist for tags with special properties, such as links.

<tagname ID="idname" CLASS="classname">

The purpose of style is to identify groups of HTML elements that can be formatted similarly, and apply the same style rules to all of them.

tagname { rules }
.classname { rules }
#idname { rules }
:pseudoclass { rules }

Complex combinations of these selectors may be used to select a more specific group of HTML objects. For example, all links <A HREF=url> with CLASS="buttonClass" will have these rules applied when they are active (clicked).

A.buttonClass:active { rules }

Selectors can also be applied in context. For example, table cells <TD> with CLASS="col3" will only have these style rules applied if they are nested within another element ( such as <TABLE> ) with ID="myTable".

#myTable     TD.col3  { rules }

How style rules are applied depends on the features of the HTML elements to which they are applied. The STYLE properties applied to an HTML tag, or element, must be consistent with its character. For example, the paragraph tag <P> has an ALIGN attribute, which can be set to left, right, or center: <P ALIGN=center>. The text-align STYLE property can be also be applied to P tag contents, set to left, right, or center: P { text-align: right; }. If both a style rule and an HTML attribute affect the same markup feature, the STYLE rule overrides the HTML attribute.

    6.4   Formatting Fonts
 
   
Style 2
A Font
of Font
Features
      Style provides a greater control of both screen and print parameters in formatting fonts.

click click click click

    6.5   Borders and Backgrounds
 
   
Style 3
      Borders can be formatted in a varity of styles, sizes, and colors. Several styles can be combined dynamically to create "stylish" buttons.

click click click click     A Border and A Background     click click click click

      Backgrounds can be color, image, both, or neither. Options provide for positioning background images in fixed positions, or allowing them to move with the content of the element.

    6.6   Arranging Elements
 
   
Style 4
Click - Double Click

Click Click
Blocks of elements can be arranged within a layer to avoid overlap.
Elements can be arranged in overlapping layers. Layers can even be hidden completely.
Style provides the capability of arranging HTML elements in complex patterns on the page.
    6.7   Cascading Style Sheets
 
   
Style 5
      Style sheets can be embedded within an HTML file, or they can be imported or linked externally. One style sheet can be linked to all the HTML files in a site, giving them a common appearance that can be changed by altering the style code in only one place. Having one style sheet to define the look of an entire site greatly facilitates site maintainance. On this page, for example, the backgrounds, fonts, and element size and arrangement are defined for all chapters in a single style file. Changing one font rule changes the appearance of the entire book.
      The great advantage of using style becomes most apparent with the cascading effect of applied style sheets. Sheets cascade when they are applied, one after another, to the same document. Thus, an overall site style can be overridden by subsequent styles applied to the same HTML element. For example, this paragraph has had the font color altered by an inline style applied after the linked style. Having the capacity to modify style contextually makes this an invaluable tool.
      Style can even be applied differentially for different viewing media. Format your page one way for screen, and another way for print. Stylesheets can also be applied to other markup languages. With a properly written site, you can apply a uniform appearance to your HTML pages and your XML pages with one stylesheet.
      Style can also be modified dynamically. The interactive features on the page above are accomplished by using JavaScript functions to alter style properties of elements on the page. Style and Script are a powerfull combination.
    6.8   References
1 Apple: Internet and Web
http://developer.apple.com/internet/

2 : Web Content
http://developer.apple.com/internet/webcontent/index.html

3 HWG: CSS Frequently Asked Questions
http://www.hwg.org/resources/faqs/cssFAQ.html

4 Microsoft Developers Network Library
http://msdn2.microsoft.com/en-us/library/default.aspx

5 : CSS Overviews and Tutorials
http://msdn2.microsoft.com/en-us/library/ms531212.aspx

6 O'Reilly Network Safari Bookshelf
http://safari.oreilly.com

7 : Core CSS
http://safari.oreilly.com/0130834564

8 Zen Garden: The Beauty of CSS Design
http://www.csszengarden.com/

9 W3C
http://www.w3.org

10 : Cascading Style Sheets
http://www.w3.org/Style/
http://www.w3.org/Style/CSS/

All Contents © 2008 Aurora Isaac. All Rights Reserved. Legal Notices.
Previous ChapterTable of ContentsNext Chapter