CSS

Unit 4: New Web Technologies: XML, XHTML, CSS

Lesson 3: CSS

Reference: CSS Tutorial

Also, check out CSS Zen Garden

What is CSS?

How it Works:

An Example

      <table>
      <tr><td bgcolor="#FFCC00" align="left">
          <font face="arial" size="2" color="red">
          <b>this is line 1</b></font></td></tr>
      <tr><td bgcolor="#FFCC00" align="left">
          <font face="arial" size="2" color="red">
          <b>this is line 2</b></font></td></tr>
      <tr><td bgcolor="#FFCC00" align="left">
          <font face="arial" size="2" color="red">
          <b>this is line 3</b></font></td></tr>
      </table>

An Example

      <table>
      <tr><td class="subtext">this is line 1</td></tr>
      <tr><td class="subtext">this is line 2</td></tr>
      <tr><td class="subtext">this is line 3</td></tr>
      </table>

With CSS You Can:

Advantages

In addition to the previous:

Disadvantage

Selectors

      <HTML>
      <HEAD>
      <style type="text/css">
        B.headline {
        color: red; 
        font-size: 22px; 
        font-family: arial; 
        text-decoration: underline  }
      </style>

      </HEAD>

      <BODY>
      <b>This is normal bold</b><br>
      <b class="headline">This is headline style bold</b>
      </BODY>

      </HTML>

Selectors

There are three types of selectors:

Tag Selectors

      HTMLtag {Property:Value;}
      <HTML>
      <HEAD>
      <style type="text/css">
        B { font-family: arial; 
            font-size: 14px; 
            color: red  }
      </style>
      </HEAD>

      <BODY>
      <b>This is a customized headline style bold</b>
      </BODY>

      </HTML>

Class Selectors

      .ClassSelector {Property:Value;}
      <HTML>
      <HEAD>
      <style type="text/css">
        .headline { font-family: arial;
                    font-size: 14px;
                    color: red   }
      </style>

      </head>

      <body>
      <b class="headline">This is a bold tag 
        carrying the headline class</b>
      <br />
      <i class="headline">This is an italics 
        tag carrying the headline class</i>
      </body>

      </html>

SPAN and DIV as carriers

Id Selectors

      #IDSelector {Property:Value;}

Example

      <HTML>
      <HEAD>
      <style type="text/css">
      #layer1 {position:absolute; left:100;top:100; z-Index:0}
      #layer2 {position:absolute; left:140;top:140; z-Index:1}
      </style>
      </HEAD>

      <BODY>
      <div ID="layer1">
      <table border="1" bgcolor="#FFCC00">
         <tr><td>THIS IS LAYER 1<br>POSITIONED AT 100,100</td></tr>
      </table>
      </div>

      <div ID="layer2">
      <table border="1" bgcolor="#00CCFF">
        <tr><td>THIS IS LAYER 2<br>POSITIONED AT 140,140</td></tr>
      </table>
      </div>
      </BODY>
      </HTML>

Grouped Selectors

      .headlines {
        font-family: arial;
        color: black;
         background: yellow;
         font-size:14pt;   }

      .sublines {
        font-family: arial;
        color: black;
        background: yellow;
        font-size:12pt;   }

      .infotext {
        font-family: arial;
        color: black;
        background: yellow;
        font-size:10pt;   }

Improved

      .headlines, .sublines, .infotext {
        font-family: arial;
        color: black;
        background:yellow;
      }

      .headlines { font-size: 14pt; }
      .sublines {  font-size: 12pt; }
      .infotext {  font-size: 10pt; }

Context Dependant Selectors

      <i><b>example</b></i>
      <b>example</b>.

The Syntax

      B {font-size:16px}
      I B {font-size:16px;}

Using Grouped and Context Dependent Selectors at the Same Time

      I B, .headlines, B .sublines {font-size:16px;}

Where to Place it

Single Tags

      It is <b style="font-size:16px;">NOT</b> me.

Single Pages

Example

      <html> <head>
      <title>MY CSS PAGE</title>
      <style type="text/css">
      .headlines, .sublines, infotext {font-face: arial;
          color: black; background: yellow; font-weight: bold;}
      .headlines {font-size:14pt;}
      .sublines {font-size:12pt;}
      .infotext {font-size: 10pt;}
      </style> </head>

      <body> <span class="headlines">Welcome</span><br>

      <div class="sublines">
      This is an example page using CSS.<br>
      The example is really simple,<br>
      and doesn't even look good,<br>
      but it shows the technique.
      </div>

      <table border="2"><tr><td class="sublines">
      As you can see:<br>
      The styles even work on tables.
      </td></tr></table>

      <div class="infotext">
      Example from EchoEcho.Com.
      </div>

      </body> </html>

Entire Sites

Example

      <html>
      <head>
      <title>MY CSS PAGE</title>
      <link rel=stylesheet href="whatever.css" type="text/css">
      </head>
      <body>
      <span class="headlines">Welcome</span><br>

      <div class="sublines">
      This is an example of a page using CSS.<br>
      The example is really simple,<br>
      and doesn't even look good,<br>
      but it shows the technique.
      </div>

      <table border="2"><tr><td class="sublines">
      As you can see:<br>
      The styles even work on tables.
      </td></tr></table>

      <hr>

      <div class="infotext">Example from EchoEcho.Com.</div>

      <hr>
      </body>
      </html>

The Style Sheet

      .headlines, .sublines, infotext {
              font-face: arial;
              color: black;
              background: yellow;
              font-weight:bold;   }

      .headlines { font-size: 14pt; }
      .sublines  { font-size: 12pt; }
      .infotext  { font-size: 10pt; }
      <link rel=stylesheet href="whatever.css" type="text/css">