4.1 CSS - Cascading Style Sheets: Main Ideas and Essential Features
4.1 CSS - Cascading Style Sheets: Main Ideas and Essential Features
What is it? Use and status Processing model Rules, selectors, generated content Usability in practise
SDPL 2003
Main usage:
to specify the representation of web pages by attaching style (fonts, colours, margins, ) to HTML/XML documents also used to specify a "WYSIWYG" presentation in some commercial XML editors, e.g., SofQuad XMetal (of Corel; Windows) Morphon (of Morphon Technologies; Java)
SDPL 2003
Level 3 (CSS3)
ongoing work; split in May 2001 into 26 modules
Notes 4.1: CSS 3
SDPL 2003
SDPL 2003
Example rules
H1 {color: blue}
/* blue text for first-level HTML headers */
H1,H2,H3 {font-style:bold;}
/* Alternative selectors grouped together: */ /* bold font for all HTML headers */
Font properties:
helvetica/serif/
normal/italic/oblique
font, (-family/-style/-variant/-weight/-size)
normal/bold/bolder/ ...
Text properties:
sub/super/...
Box properties:
for controlling size, margins, borders etc. of boxes (see later)
Classification properties:
display (values: block | inline | list-item | none), white-space (values: normal | pre | nowrap), list-style, (-type/-image/-position)
decimal/lower-alpha/ disk/...
SDPL 2003 Notes 4.1: CSS
inside/outside
SDPL 2003
SDPL 2003
Inheritance (1/2)
SDPL 2003
11
Inheritance (2/2)
and rules
chap { font-size: 12pt; font-family: serif } title { font-size: 150% } Now both title and section will be formatted using a serif font, but title with a 50% larger font size
Notes 4.1: CSS 12
SDPL 2003
Transcription maps document elements into nested rectangular boxes, which have
a core content area optional surrounding margin, border and padding areas controlled by corresponding properties margin, border and padding, and width and height (last two most useful for scaling images)
SDPL 2003
13
Box properties:
width, height, float, clear; margin, (-top/-right/-bottom/-left); padding, (-top/-right/-bottom/-left); border-width, (-top-/-right-/-bottom-/-left-); border-color, border-style; border, (-top/-right/-bottom/-left);
SDPL 2003
15
Boxes: Example
Box for chapter margin padding margin padding Content for title margin padding Content for section
SDPL 2003
16
Block-level
formatted as boxes separated by line breaks default formatting of, e.g., P,H1,H2 in HTML specified by display:block display:list-item -> block preceded by list-item marker
SDPL 2003
Application of style rules determined by matching selectors to elements of the document tree
CSS2 adds
a universal selector * matching any element tests for attributes:
fig[file="fig1.jpg"]: figure with given value for attribute file *[file="fig1.jpg"]: any element with that value for attribute file fig[file]: element fig with attribute file
Notes 4.1: CSS 18
SDPL 2003
CSS2 adds
direct inclusion: Parent > Child conditions on siblings: E + A: element A preceded by an element satisfying selector E B:first-child: B as the first element child
SDPL 2003
19
SDPL 2003
20
CSS2 adds insertion of generated content before and after selected elements Example:
Number theorems within each chapter Precede each theorem by "Theorem" and its number Follow the theorem by a little box
SDPL 2003
21
Also possible to include attribute values of the selected element in generated content using attr(Name)
Notes 4.1: CSS 22
SDPL 2003
Limitations of CSS
SDPL 2003
23
Limitations of CSS
Non-programmable
no decision structures unable to store calculated quantities non-extensible > relatively simple
Western-language orientation (left-to-right) XSL allows unrestricted transformations of the document to precede a CSS-like formatting
Notes 4.1: CSS 24
SDPL 2003
Browser Implementations
MS policy of developing own extensions, instead of completing conformance with accepted recommendations strongly criticised
SDPL 2003 Notes 4.1: CSS 25