Styling the New Web

Web Usability with Style Sheets

Steven Pemberton

Plan for the day

HTML and SGML

Contamination

Style Sheets

CSS

Levels

Check your log files!

Why is CSS good for usability?

Why is CSS good for the author?

Using CSS

External file:

<html>
<head>
<link rel="stylesheet"
      type="text/css"
      href="style.css">
</head>
<body> ...</body>
</html>

Inline style is also possible

You can also put your style sheets in the head of your HTML document:

<head>

<style type="text/css"> <!--     h1 { color: blue } --> </style> </head>

The comment symbols <!-- --> are optional: they hide the style sheet from old browsers.

For many reasons, it is better to use external style sheets

Style sheets for XML

For XML use a processing instruction:

    <?xml-stylesheet type="text/css" href="sheet.css"?>

Put before first element of the document

HTML Style Attributes

HTML also allows you to use a STYLE attribute:

<P STYLE="color: red">Stop!</P>

This is bad practice, and undoes many of the advantages of CSS.

Doesn't (necessarily) work for XML.

Warning about HTML: <p>

Structure of CSS1

Comments

Basic Selectors

Warning about HTML: case

Examples

Styling text

font-size

Use relative sizes, or the named absolute sizes

Warning about 'initial values'

Lengths

font-weight

font-style

font-family

You should always end with a generic family

Colours: color and background-color

Practical 1

Class Selectors

Use of HTML: span

ID Selectors

Used rarely; class is more useful

Contextual Selectors

These allow you to address the nesting of the document:

h1 { font-weight: bold }
em { font-style: italic }

<h1><em>Now</em> is the time!</h1>

Þ Now is the time

h1 em { font-weight: normal }

Þ Now is the time

Examples of contextual selectors

Inheritance

Use of HTML: <div>

display

Example of display: none

text-align

Box model

Content

Margins: margin-top, -right, -bottom, -left

Warnings about use of margins

body {margin-left: 4em}
h1 {margin-left: -4em}
<h1> typically has a larger font-size to <body>, therefore the '-4em' on h1 is larger than the 4em on <body>
body {margin-left: 4em}
h1 {margin-left: 0}
h1 will have the same indent as the body (margins are relative to the parent element, not the screen)

Shortcuts: margin

Use of margins

Padding: padding-top, -right, -bottom, -left

Example

Borders: border-top-width etc.

Shorthand: border-width

border-style

 

border-color

Shorthands: border-top, -right, -bottom, -left

One last border shorthand: border

Beware when using shorthands!

Usage of borders

Height and width

The height and width of elements is normally determined by context or by the element itself.

For instance, for text, the width is determined by the width of the window, and the height by the amount of text.

Images have an inbuilt size.

You can change these defaults with the height and width properties.

width

Auto values for box model

Practical 2

Text properties: line-height

Warning about line-height

body {font-size: 10pt; line-height: 1.2}
h1 {font-size: 20pt}
  • h1 has a line-height of 20pt x 1.2 = 24pt
  • body {font-size: 10pt; line-height: 1.2em}

    h1 {font-size: 20pt}

    text-decoration

    text-indent

    word-spacing, letter-spacing

    vertical-align

    Background properties: background-image

    background-position

    background-repeat

    background-attachment

    Pseudo Classes: Anchors

    a:link { color: blue }
    a:visited { color: #f0f }
    a:active { color: red }
    
    a:link img { border-style: solid; border-color: blue }
    
    a:hover {color: red}
    

    Note on <a>

    a {color: green}
    a:link {color: blue}
    

    Beware!

    p {color: black}
    a:link {color: blue}
    

    "Click here" will be blue.

    Pseudo element:
    first-line, first-letter

    p:first-line {font-variant: small-caps}
    p:first-letter {color: red}
    

    Float

    Use of float

     

    clear

     

    Use of clear

     

    font-variant

    text-transform

    font

    white-space

    list-style-type

    list-style-image

    list-style-position

    list-style

    This is a shorthand

    Cascading

    Selectivity of selectors

    Practical 3

    Implementation

    Level Compatibility

    Ignore rule: *[width] {font-size: 10pt}

    Ignore declaration: p {overflow: hidden; color: blue}

    Ignore declaration: h2 {display: run-in; color: blue}

    CSS2 and 3

    Later areas of work include:

    CSS2

    (CSS2)

    CSS3

    Where?

    The definition of CSS1 can be found at:

    http://www.w3.org/TR/REC-CSS1

    The definition of CSS2 is at

    http://www.w3.org/TR/REC-CSS2/

    Future Markup

    XML

    Consequences

    Consequences 2

    Consequence of XML

    So do we still need HTML?

    HTML as XML application

    Differences HTML:XHTML

    Example

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head><title>Virtual Library</title></head>

    <body>

    <p>Moved to <a href="http://vlib.org/">vlib.org</a>. </p>

    </body>

    </html>

    Namespaces

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head><title>A Math Example</title></head>

    <body>

    <p>The following is MathML markup:</p>

    <math xmlns="http://www.w3.org/TR/REC-MathML">

    <apply><log/><logbase><cn> 3 </cn> </logbase>

    <ci> x </ci>

    </apply>

    </math>

    </body></html>

    Transition

    Examples of Guidelines

    Result

    Practical 4

    Overview of properties, with examples and defaults

    Overview...

    Overview of box properties