Collected by
Elizabeth Janson

Home Page

Comments and Selectors

 

Comments

Textual comments in CSS style sheets are similar to those in the C programming language, and use   /* secret message */  .
For example
EM { color: red }  /* red, really red!! */

Selectors

The selector is the link between the HTML document and the style sheet. Style sheet selectors are the code that preceeds the curly bracketed definitions.

There are five different kinds of selectors that you can use to add style to your web pages.

  • Universal Selector
  • Type Selectors use HTML tags (now called 'elements').
    • Simple
    • Contextual
    • Grouping
  • Attribute Selectors use names
    • ID
    • CLASS
  • New Element Selectors
    • DIV for blocks in the layout
    • SPAN for in-line changes, inside a block.
  • External Selectors
    • Pseudo-Classes
    • Pseudo-Elements
In summary,
  • The most simple selector is only an element name, and matches any element of that type
  • The element name can optionally be followed by a hash mark (#) and an ID value, matching the element of the specified type with that ID.
  • It can also be optionally followed by a period (.) and a CLASS value, matching all elements of the specified type with that CLASS.
  • It can also be optionally followed by a colon (:) and a pseudoclass, matching all elements of the specified type belonging to that pseudoclass.
  • If the element name is omitted when an ID, CLASS or pseudoclass is specified, then the selector matches all elements, of any type, that have that ID, CLASS or pseudoclass.
The browser interpreting the Style Sheet causes us to consider two other aspects, concerning how to cope with clashes.
  • Inheritance
  • Errors

Universal selector

bug hiding as universal selector not supported Note that because of inheritance, discussed later on, and the fact that most browsers do not support the universal selector, you should rarely, if ever, use it, despite these notes from W3C.

The universal selector, written "*", represents the qualified name of any element type. It represents then any single element in the document tree in any namespace (including those without any declared namespace) if no default namespace has been specified. If a default namespace has been specified, see below Universal selector and Namespaces.

If the universal selector is not the only component of a sequence of simple selectors, the * may be omitted. For example:

*[lang=fr] and [lang=fr] are equivalent,
*.warning and .warning are equivalent, (example using CLASS type names)
*#myid and #myid are equivalent. (example using ID type names)

Warning : it is recommended that the *, representing the universal selector, not be omitted.

Email
CSS begins here
Next are Type Selectors

This page is part of Elizabeth Janson's web site

http://www.oocities.org/elizatk/index.html

My other sites are the Anglican Parish of Northern Mallee,
Tetbury residents in the Eighteenth Century
my Australian Family History and Barrie, our Family Poet.