
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:
| ||||||||
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.
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.
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.
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:
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:
| ||||||||
6.3 Style Selectors | ||||||||
|
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.
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 | ||||||||
|
| |||||||
6.5 Borders and Backgrounds | ||||||||
|
Borders can be formatted in a varity of styles, sizes, and colors.
Several styles can be combined dynamically to create "stylish" buttons.
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 | ||||||||
|
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 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
3
HWG: CSS Frequently Asked Questions
4
Microsoft Developers Network Library
5
: CSS Overviews and Tutorials
6
O'Reilly Network Safari Bookshelf
7
: Core CSS
8
Zen Garden: The Beauty of CSS Design
9
W3C
10
: Cascading Style Sheets | ||||||||
| All Contents © 2008 Aurora Isaac. All Rights Reserved. Legal Notices. | ||||||||