CSS Frequently Asked Questions - The HTML Writers Guild (original) (raw)

#abc123 {color: red; background: black}
<P ID=abc123>This and only this element can be identified as abc123</P>
Table of Contents

  1. A[title="attribute element"] {text-decoration: underline}
    The A elements containing the TITLE attribute with a value that is an exact match of the specified� value, which in this example is 'attribute element', will be underlined
  2. A[title~="attribute"] {text-decoration: underline}
    The A elements containing the TITLE attribute with a value containing the specified word, which in this example is 'attribute', will be underlined
    Table of Contents

������� font-style: italic;
������� font-variant: small-caps;
������� font-size: 160%;
������� font-family: serif}
can be all shorthanded to a space separated list:
H1 {font: bold italic small-caps 160% serif}
Note: To make things even simpler the line-height property can be specified together with the font-size property:
H1 {font: bold italic small-caps 160%/170% serif}
Table of Contents

  1. The rule P {color: red} will display red text in all paragraphs. By classifying the selector P different style can be attached to each class allowing the display of some paragraphs in one style and some other paragraphs in another style.
  2. A class can also be specified without associating a specific element to it and then attached to any element which is to be styled in accordance with it's declaration. All elements to which a specific class is attached will have the same style.
    To classify an element add a period to the selector followed by an unique name. The name can contain characters a-z, A-Z, digits 0-9, period, hyphen, escaped characters, Unicode characters 161-255, as well as any Unicode character as a numeric code, however, they cannot start with a dash or a digit. (Note: in HTML the value of the CLASS attribute can contain more characters). (Note: text between /* and */ are my comments).
    CSS
    P.name1 {color: red} /* one class of P selector */ P.name2 {color: blue} /* another class of P selector */ .name3 {color: green} /* can be attached to any element */
    HTML
    `

    This paragraph will be red

    This paragraph will be blue

    This paragraph will be green

  3. This list item will be green
  4. ` It is a good practice to name classes according to their function than their appearance; e.g. `P.fotnote` and not `P.green`. In CSS1 only one class can be attached to a selector. CSS2 allows attaching more classes, e.g.: P.name1.name2.name3 {declaration}

    This paragraph has three classes attached

    [Table of Contents](#toc)
  1. Find all declarations that apply to a specific selector/property
    and
    Declare the specified style if the selector matches the element
    if there isn't any
    Let the element inherit its parent property
    if there isn't any
    Use initial value
  2. Sort by weight (! important)
    Increased weight take precedence over normal weight
  3. Sort by origin
    Rules with normal weight declared in author's style sheet will override rules with normal weight declared in user's personal style sheets
    Rules with increased weight declared in user's personal style sheet will override rules with normal weight declared in author's style sheet
    Rules with increased weight declared in author's style sheet will override rules with increased weight declared in user's personal style sheets
    Author's and user's rules will override UA's default style sheet.
  4. Sort by selector's specificity
    More specific selector will override less specific one:
    ID-selector (most specific), followed by
    Classified contextual selectors (TABLE P EM.fot)
    Class selectors (EM.fot)
    Contextual selectors - the "lower down" the more weight, (TABLE P EM), (TABLE P EM STRONG) - STRONG has more weight than EM.
  5. Sort by order specified
    If two rules have the same weight, the latter specified overrides ones specified earlier. Style sheets are sorted out as follows:
    The STYLE attribute (inline style) overrides all other styles
    The Style element (embedded style) overrides linked and imported sheets
    The LINK element (external style) overrides imported style
    The @import statement - imported style sheets also cascade with each other in the same order as they are imported
    Table of Contents

This page is maintained by eva@algonet.se. Last updated on 2 November 1999.
Copyright © 1998 by the HTML Writers Guild, Inc.