Cascading Style Sheets




CS174

Chris Pollett

Sep 12, 2022

Outline

Introduction

Levels of Style Sheets

Basics of Styles

Examples of Simple Selectors

h1 {font-size: 24pt;} /* would apply to all h1 tags in the document */

h2, h3 {font-size: 14pt;} /* notice applies to both h2 and h3 tags */

You can also specify that styles should only apply to elements in certain positions within the file:

body b i {font-size: 30pt;} /* only for bolded italic'd text within body of HTML*/

Quiz

Which of the following is true?

  1. A meta tag can be used to specify the favicon of a webpage.
  2. The link tag is used to make a clickable link between one web page and another in HTML.
  3. All form data is sent from a browser using the HTTP POST method.

Class selectors

ID Selectors

Reset Styles, !important

Pseudo Classes

What values can a property have?

Color, Fonts, and Text Decoration

Colors
  • You should remember when specifying colors that they might look different on different machines / monitors. There is a list of 216 so called web-safe colors on Wikipedia.
  • To specify the foreground color of a tag you can set the color property. For example, div.changed {color: red} <div class="changed"><p>first paragraph that's new</p><p>2nd...</p></div>
  • To specify the background you use the background-color property
Fonts
There are several properties of fonts that you can control.
  • font-family (examples: Arial, Times, Courier)
  • font-size (examples: 20pt, 15px, xx-small, x-small, small, medium, large, smaller, larger, etc)
  • font-style (example: italic, oblique)
  • font-weight (example: bold, bolder)
Text-Decoration
The text-decoration property can be further used to control how text looks. Some values are line-through, overline, underline, and none.

List Properties

Alignment of Text