~~SLIDESHOW~~ ====== The Presentation Layer ====== HTML is designed to define only the structure of a web document. The cascading style sheet (CSS) standard provides a way to define how a document, or collection of documents, will look. Cascading style sheets also allow certain user interface effects to be achieved. * This part of the lecture introduces the concept of a style sheet * Explains how style sheets fit into the philosophy of HTML * And describes the structure of HTML documents. ===== Cascading Style Sheets ===== Applying a common "look and feel" to a collection of web documents. * [[eg-259:css#cascading_style_sheets|Introduction to CSS]] * [[eg-259:css#introduction_to_css|Levels of Style Sheets]] * [[eg-259:css#style_specification_formats|Style Specification Formats]] * [[eg-259:css#selector_forms|Selector Forms]] * [[eg-259:css#property_value_forms|Property Value Forms]] * [[eg-259:css#font_properties|Font Properties]] * [[eg-259:css#list_properties|List Properties]] * [[eg-259:css#colours|Colours]] * [[eg-259:css#alignment_of_text|Alignment of Text]] * [[eg-259:css#the_box_model|The Box Model]] * [[eg-259:css#background_images|Background images]] * [[eg-259:css#the_span_and_div_tags|The and
tags]] ===== Introduction to CSS ===== * Provides the means to control and change presentation of HTML documents * The CSS1 specification was developed in 1996 * CSS2 was released in 1998 * Support for [[eg-259:css3|CSS3]] is gradually being added to modern browsers. * CSS is not technically HTML, but can be embedded in HTML documents * Style sheets allow you to impose a standard style on a whole document, or even a whole collection of documents * Style is specified for a tag by the values of its properties ===== Levels of Style Sheets ===== * There are three levels of style sheets - //In-line styles sheets// -- specified for a specific occurrence of a tag and apply only to that tag - //Document-level style sheets// -- apply to the whole document in which they appear - //External style sheets// -- can be applied to any number of documents ---- * When more than one style sheet applies to a specific tag in a document, the lowest level style sheet has precedence * In a sense, the browser searches for a style property specification, starting with in-line, until it finds one (or there isn't one) * In-line style sheets appear in the tag itself and apply only to that tag. * Document-level style sheets appear in the head of the document * External style sheets are in separate files, potentially on any server on the Internet * **Note**: Use of in-line style sheets is fine-grain, which should be used sparingly as otherwise it defeats the purpose of style sheets –- uniform style ===== Style Specification Formats ===== Format depends on the level of the style sheet * [[eg-259:css#in-line_style_sheets|In-line Style Sheets]] * [[eg-259:css#document-level_style_sheets|Document-level Style Sheets]] * [[eg-259:css#external_style_sheets|External Style Sheets]] ===== In-line Style Sheets ===== * Style sheet appears as the value of the ''style'' attribute style = "property_1: value_1; property_2: value_2; . . .; property_n: value_n" ---- * Style sheet appears as a list of rules that are the content of a '' * Form of the rules: ''selector {list of property/values}'' * Each property/value pair has the form: ''property: value'' * Pairs are separated by semicolons, just as in the value of a ''

Your name:

===== Property Value Forms ===== * There are 60 different properties in 7 categories: * Fonts * Lists * Alignment of text * Margins * Colours * Backgrounds * Borders [ [[eg-259:html5|Jump to HTML 5]] ] ===== Forms of Property Value ===== * //Keywords// -- ''left'', ''small'', etc * //Length// -- numbers, maybe with decimal points and a unit specification * //Percentage// -- just a number followed immediately by a percent sign * //URL values// url(protocol://server/pathname) * //Colours// -- colour name, or Red Green Blue values ''rgb(n1, n2, n3)'', or Hexadecimal form ''#XXXXXX'' ---- //**Notes**// * The names of keyword properties are not case sensitive * Length Units: px -- pixels in -- inches cm -- centimeters mm -- millimeters pt -- points pc -- picas (12 points) em -- height of the letter 'm' ex-height -- height of the letter 'x' * No space is allowed between the number and the unit specification, e.g. ''1.5 in'' is illegal! * Property values are inherited by all nested tags, unless overridden ===== Font Properties ===== * [[eg-259:css#font_family|Font family]] * [[eg-259:css#font_size_style_and_weight|Font size, style and weight]] * [[eg-259:css#the_font-property|The font property]] * [[eg-259:css#examples_of_the_use_of_font|Examples of the use of font]] ===== Font family ===== * Value is a list of font names -- browser uses the first in the list it has * ''font-family'': ''Arial'', ''Helvetica'', ''Courier'' * Generic fonts: ''serif'', ''sans-serif'', ''cursive'', ''fantasy'', and ''monospace'' (defined in CSS) * If a font name has more than one word, it should be single-quoted as in '''Times New Roman''' ---- * Browser has a specific font for each generic font ===== Font size, style and weight ===== * ''font-size'' -- Possible values: a length number or a name such as ''smaller'', ''xx-large'', etc. * ''font-style'' -- ''italic'', ''oblique'', ''normal'' * ''font-weight'' -- degrees of boldness: ''bolder'', ''lighter'', ''bold'', ''normal'' ---- The ''font-weight'' can be specified as a multiple of 100 (100 – 900) ===== The font property ===== * For specifying a list of font properties you can use the ''font'' property: font: bolder 14pt Arial Helvetica * Order must be: ''style'', ''weight'', ''size'', ''name(s)'' ===== Examples of the Use of Font ===== * Example 1: [[/eg-259/examples/lecture2/fonts.html|fonts.html]] * Example 2: [[/eg-259/examples/lecture2/fonts2.html|fonts2.html]]: styles applied with external stylesheet [[/eg-259/examples/lecture2/styles.css|styles.css]] ---- //Example 1// Font properties

If a job is worth doing, it's worth doing right.

Two wrongs don't make a right, but they certainly can get you in a lot of trouble.

Chapter 1 Introduction

1.1 The Basics of Computer Networks

//Example 2// The HTML code [[/eg-259/examples/lecture2/fonts2.html|fonts2.html]]: External style sheets

If a job is worth doing, it's worth doing right.

Two wrongs don't make a right, but they certainly can get you in a lot of trouble.

Chapter 1 Introduction

1.1 The Basics of Computer Networks

The External Stylesheet [[/eg-259/examples/lecture2/styles.css|styles.css]]: /* styles.css - an external style sheet for use with fonts2.html */ p.big { font-size: 14pt; font-style: italic; font-family: 'Times New Roman'; } p.small { font: 10pt bold 'Courier New'; } h2 { font-family: 'Times New Roman'; font-size: 24pt; font-weight: bold } h3 { font-family: 'Courier New'; font-size: 18pt } //Note// how much smaller, and easier to understand, is the HTML **without** the stylesheet. Also, note that the stylesheet can be used with a collection of HTML documents. ===== Some Additional Properties Related to Fonts ===== * The ''text-decoration'' property: ''line-through'', ''overline'', ''underline'', ''none''. See [[/eg-259/examples/lecture2/fonts3.html|fonts3.html]]. * ''letter-spacing'': value is any length property value ---- Example3 Text decoration

This illustrates line-through

This illustrates overline

This illustrates underline

===== List properties ===== * [[eg-259:css#list_style_typeunordered_lists|List style type: unordered lists]] * [[eg-259:css#list_style_typeordered_lists|List style type: ordered lists]] ===== List style type: unordered lists ===== * Bullet can be a ''disc'' (default), a ''square'', or a ''circle'' * Set it on either the ''