Table of Contents

~~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.

Cascading Style Sheets

Applying a common “look and feel” to a collection of web documents.

Introduction to CSS

Levels of Style Sheets


Style Specification Formats

Format depends on the level of the style sheet

In-line Style Sheets

    style = "property_1: value_1;
             property_2: value_2;
             . . .;
             property_n: value_n"

Document-level style sheets

       <style>
           rule list
       </style>

External style sheets

      <head>
       <link rel="stylesheet" href="http://www.swan.ac.uk/style.css" />
      </head>

Selector Forms

Simple Selector Forms

  h1, h3
  p
  ol ol li

Class Selector Forms

     p.narrow {property/value list}
     p.wide {property/value list}

      <p class = "narrow">    <p class = "wide">
       . . .                   . . .
      </p>                    </p>
      . . .

Generic Selector Forms

  .really-big { . . . }
       <h1 class = "really-big"> . . . </h1>
       . . .
       <p class = "really-big"> . . . </p>

id Selector Forms

   #section14 {font-size: 20;}

Pseudo Classes


the :hover and :focus pseudo classes
<!DOCTYPE html>
<!-- pseudo.html
Illustrates the :hover and :focus pseudo classes
-->
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title> Checkboxes </title>
    <style type="text/css">
      input:hover {
        color: red;
      }
      input:focus {
        color: green;
      }
    </style>
  </head>
  <body>
    <form action="">
      <p>
        Your name:
        <input type="text" placeholder="type something to see the effect" />
      </p>
    </form>
  </body>
</html>

Property Value Forms

[ Jump to HTML 5 ]

Forms of Property Value


Notes

       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'

Font Properties

Font family


Font size, style and weight

—-

The font-weight can be specified as a multiple of 100 (100 – 900)

The font property

    font: bolder 14pt Arial Helvetica

Examples of the Use of Font


Example 1

example to illustrate font properties
<!DOCTYPE html>
<!-- fonts.html
An example to illustrate font properties
-->
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title> Font properties </title>
    <style>
      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
      }
    </style>
  </head>
  <body>
    <p class = "big">
      If a job is worth doing, it's worth doing right.
    </p>
    <p class = "small">
      Two wrongs don't make a right, but they certainly
      can get you in a lot of trouble.
    </p>
    <h2> Chapter 1 Introduction </h2>
    <h3> 1.1 The Basics of Computer Networks </h3>
  </body>
</html>

Example 2

The HTML code fonts2.html:

example to test external style sheets
<!DOCTYPE html>
<!-- fonts2.html
An example to test external style sheets
-->
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title> External style sheets </title>
    <link rel = "stylesheet" href = "styles.css" />
  </head>
  <body>
    <p class = "big">
      If a job is worth doing, it's worth doing right.
    </p>
    <p class = "small">
      Two wrongs don't make a right, but they certainly
      can get you in a lot of trouble.
    </p>
    <h2> Chapter 1 Introduction </h2>
    <h3> 1.1 The Basics of Computer Networks </h3>
  </body>
</html>

The External Stylesheet styles.css:

external style sheet for use with fonts2.html
/* 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.


Example3

example to illustrate some additional font properties
<!DOCTYPE html>
<!-- fonts3.html
An example to illustrate some additional font properties
-->
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title> Text decoration </title>
    <style>
      p.through {
        text-decoration: line-through;
      }
      p.over {
        text-decoration: overline;
      }
      p.under {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <p class = "through">
      This illustrates line-through
    </p>
    <p class= "over">
      This illustrates overline
    </p>
    <p class = "under">
      This illustrates underline
    </p>
  </body>
</html>

List properties

List style type: unordered lists

      <h3> Some Common Single-Engine Aircraft </h3>
      <ul style = "list-style-type: square">
        <li> Cessna Skyhawk </li>
        <li> Beechcraft Bonanza </li>
        <li> Piper Cherokee </li>
      </ul>
        <li style = "list-style-image:url(bird.jpg)">

List style type: ordered lists

Property value Sequence type First four
decimal Arabic numerals 1, 2, 3, 4
upper-alpha UC letters A, B, C, D
lower-alpha LC letters a, b, c, d
upper-roman UC Roman I, II, III, IV
lower-roman LC Roman i, ii, iii, iv

<!DOCTYPE html>
<!-- sequence_types.html
An example to illustrate sequence type styles
-->
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title> Sequence types </title>
    <style>
      ol {
        list-style-type: upper-roman;
      }
      ol ol {
        list-style-type: upper-alpha;
      }
      ol ol ol {
        list-style-type: decimal;
      }
    </style>
  </head>
  <body>
    <h3> Aircraft Types </h3>
    <ol>
      <li>
        General Aviation (piston-driven engines)
        <ol>
          <li>
            Single-Engine Aircraft
            <ol>
              <li>
                Tail wheel
              </li>
              <li>
                Tricycle
              </li>
            </ol>
          </li>
          <li>
            Dual-Engine Aircraft
            <ol>
              <li>
                Wing-mounted engines
              </li>
              <li>
                Push-pull fuselage-mounted engines
              </li>
            </ol>
          </li>
        </ol>
      </li>
      <li>
        Commercial Aviation (jet engines)
        <ol>
          <li>
            Dual-Engine
            <ol>
              <li>
                Wing-mounted engines
              </li>
              <li>
                Fuselage-mounted engines
              </li>
            </ol>
          </li>
          <li>
            Tri-Engine
            <ol>
              <li>
                Third engine in vertical stabilizer
              </li>
              <li>
                Third engine in fuselage
              </li>
            </ol>
          </li>
        </ol>
      </li>
    </ol>
  </body>
</html>

Colours

Named Colours

There is a set of 16 colours that are guaranteed to be displayable by all graphical browsers on all colour monitors

black 000000 green 008000
silver C0C0C0 lime 00FF00
gray 808080 olive 808000
white FFFFFF yellow FFFF00
maroon 800000 navy 000080
red FF0000 blue 0000FF
purple 800080 teal 008080
fuchia FF00FF aqua 00FFFF

The Web Palette

The Full Palette

Using Colours


Example of the use of the color property:

example to illustrate the color property
<!DOCTYPE html>
<!-- back_color.html
An example to illustrate the color property
-->
<html lang="en">
  <head>
    <meta charset="utf=8" />
    <title> background-color </title>
    <style>
      th.red {
        color: red
      }
      th.orange {
        color: orange
      }
    </style>
  </head>
  <body>
    . . .
    <table border = "5">
      <tr>
        <th class = "red"> Apple </th>
        <th class = "orange"> Orange </th>
        <th class = "orange"> Screwdriver </th>
      </tr>
    </table>
  </body>
</html>

Example of the use of the background-color property:

example to illustrate the background-color property
<!DOCTYPE html>
<!-- back_color.html
An example to illustrate the background-color property
-->
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title> background-color </title>
    <style>
      p.redback {
        font-size: 24pt;
        color: blue;
        background-color: red;
      }
    </style>
  </head>
  <body>
    <p class = "redback">
      To really make it standout, use a red background!
    </p>
  </body>
</html>

Alignment of Text


If we have an element we want on the right, with text flowing on its left, we use the default text-align value (left) for the text and the right value for float on the element we want on the right

Example: float.html

example to illustrate the float property
<!DOCTYPE html>
<!-- float.html
An example to illustrate the float property
-->
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title> The float property </title>
    <style>
      img {
        float: right
      }
    </style>
  </head>
  <body>
    <p>
      <img src = "c210new.jpg" alt = "Picture of a Cessna 210" />
    </p>
    <p>
      This is a picture of a Cessna 210. The 210 is the flagship
      single-engine Cessna aircraft. Although the 210 began as a
      four-place aircraft, it soon acquired a third row of seats,
      stretching it to a six-place plane. The 210 is classified
      as a high-performance airplane, which means its landing
      gear is retractable and its engine has more than 200
      horsepower. In its first model year, which was 1960,
      the 210 was powered by a 260-horsepower fuel-injected
      six-cylinder engine that displaced 471 cubic inches.
      The 210 is the fastest single-engine airplane ever
      built by Cessna.
    </p>
  </body>
</html>

Typical results: An example of the use of float

The Box Model

The box model

The Box Model – Borders


example of a simple table with various borders
<!DOCTYPE html>
<!-- borders.html
An example of a simple table with various borders
-->
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title> Table borders </title>
    <style>
      table {
        border-top-width: medium;
        border-bottom-width: thick;
        border-top-color: red;
        border-bottom-color: blue;
        border-top-style: dotted;
        border-bottom-style: dashed;
      }
      p {
        border-style: dashed;
        border-width: thin;
        border-color: green
      }
    </style>
  </head>
  <body>
    <table border = "5">
      <caption>
        Fruit Juice Drinks
      </caption>
      <tr>
        <th></th>
        <th> Apple </th>
        <th> Orange </th>
        <th> Screwdriver </th>
      </tr>
      <tr>
        <th> Breakfast </th>
        <td> 0 </td>
        <td> 0 </td>
      </tr>
      <tr>
        <th> Lunch </th>
        <td> 1 </td>
        <td> 0 </td>
        <td> 0 </td>
      </tr>
      <tr>
        <th> Dinner </th>
        <td> 0 </td>
        <td> 0 </td>
        <td> 1 </td>
      </tr>
    </table>
    <p>
      Now is the time for all good Web programmers to
      learn to use style sheets.
    </p>
  </body>
</html>

The Box Model – Margins

     <img src = "c210.jpg " 
           style = "float: right;
                    margin-left: 0.35in;
                    margin-bottom: 0.35in" />

The Box Model – Padding


example to illustrate margins and padding
<!DOCTYPE html>
<!-- marpads.html
An example to illustrate margins and padding
-->
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title> Table borders </title>
    <style>
      p.one {
        margin: 0.2in;
        padding: 0.2in;
        background-color: #C0C0C0;
        border-style: solid;
      }
      p.two {
        margin: 0.1in;
        padding: 0.3in;
        background-color: #C0C0C0;
        border-style: solid;
      }
      p.three {
        margin: 0.3in;
        padding: 0.1in;
        background-color: #C0C0C0;
        border-style: solid;
      }
      p.four {
        margin: 0.4in;
        background-color: #C0C0C0;
      }
      p.five {
        padding: 0.4in;
        background-color: #C0C0C0;
      }
    </style>
  </head>
  <body>
    <p>
      Here is the first line.
    </p>
    <p class = "one">
      Now is the time for all good Web programmers to
      learn to use style sheets.
      <br />
      [margin = 0.2in,
      padding = 0.2in]
    </p>
    <p class = "two">
      Now is the time for all good Web programmers to
      learn to use style sheets.
      <br />
      [margin = 0.1in,
      padding = 0.3in]
    </p>
    <p class = "three">
      Now is the time for all good Web programmers to
      learn to use style sheets.
      <br />
      [margin = 0.3in,
      padding = 0.1in]
    </p>
    <p class = "four">
      Now is the time for all good Web programmers to
      learn to use style sheets.
      <br />
      [margin = 0.4in,
      no padding, no border]
    </p>
    <p class = "five">
      Now is the time for all good Web programmers to
      learn to use style sheets.
      <br />
      [padding = 0.4in,
      no margin, no border]
    </p>
    <p>
      Here is the last line.
    </p>
  </body>
</html>

Background Images


example to illustrate background images
<!DOCTYPE html>
<!-- back_image.html
An example to illustrate background images
-->
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title> Background images </title>
    <style>
      body {
        background-image: url(c172.gif);
      }
      p {
        margin-left: 30px;
        margin-right: 30px;
        margin-top: 50px;
        font-size: 14pt;
        color: yellow
      }
    </style>
  </head>
  <body>
    <p >
      The Cessna 172 is the most common general aviation airplane
      in the world. It is an all-metal, single-engine piston,
      high-wing four-place monoplane. It has fixed-gear and is
      categorized as a non-high-performance aircraft. The current
      model is the 172R.
      The wingspan of the 172R is 36'1". Its fuel capacity is 56
      gallons in two tanks, one in each wing. The takeoff weight
      is 2,450 pounds. Its maximum useful load is 837 pounds.
      The maximum speed of the 172R at sea level is 142 mph.
      The plane is powered by a 360 cubic inch gasoline engine
      that develops 160 horsepower. The climb rate of the 172R
      at sea level is 720 feet per minute.
    </p>
  </body>
</html>

The <span> and <div> tags

     <p>
       Now is the <span> best time </span> ever!
     </p>

      <style type = "text/css">?
             bigred {font-size: 24pt;
                     font-family: Ariel; 
                     color: red}
      </style>
      <p>
         Now is the
            <span class = "bigred">
         best time </span> ever!
      </p>

Use of the span tag

The <span> and <div> tags (continued)


By default <div> is a block-level tag and <span> is an in-line tag, although these definitions can be overridden by style declarations.

The Structural and Presentation Layers