IS 337: Website Administration

Lecture for September 24: CSS Selectors

+
-

Topics

Rolling Your Own Tags

  • <div> (block level) and <span> (inline)
    • class attribute (appearance)
    • id attribute (layout)

CSS Selectors

  • Selectors
    • Universal selector
      • syntax: *
      • implicit syntax:  
      • use: CSS reset; in combination with another selector
    • Element type selector
      • syntax: name of HTML tag
      • use: change properties of the tag throughout document
    • Class selector
      • syntax: tag.identifier
      • tag can be universal, explicit or implicit
      • can have multiple .identifiers
      • use: change properties of tags with class set to identifier
    • ID selector
      • syntax: tag#identifier
      • tag can be universal, explicit or implicit
      • use: change properties of tag (singular!) with id set to identifier
    • Attribute selector (and CSS3 attribute selector)
      • syntax: tag[identifier]
      • syntax: tag[identifier="value"]
      • tag can be universal, explicit or implicit
      • use: change properties of tags with identifier attribute (set to value)
      • instead of =:
        • |= for prefix match of hyphenated value (what?!)
        • ~= for match in list of space-separated words
        • ^= for prefix match (CSS3)
        • $= for suffix match (CSS3)
        • *= for substring match (CSS3)

Grouping and Combining CSS Selectors

  • Selector grouping
    • syntax: comma-separated list of selectors
    • use: logical OR
  • Combinators
    • Descendant selector
      • syntax: whitespace-separated list of selectors
      • use: use as a path in the DOM, format those nodes as specified
      • note: descendant, not chlid
    • Child selector
      • syntax: parent>child
      • use: use as a path in DOM, format those nodes as specified
      • note: child
    • Adjacent sibling selector
      • syntax: selector+sibling
      • use: use as a path in DOM, format those nodes as specified
      • note: "adjacent sibling" means "same parent" and "immediately following"
    • General sibling selector
      • syntax: selector~sibling
      • use: use as a path in DOM, format those nodes as specified
      • note: "general sibling" means "same parent" and "all following"
    • Pseudoclasses

Readings and Resources

Quick Written Assignment for Next Time

Consider the department's home page. Write down the following CSS selectors:

  • A selector to format all news teasers.
  • A selector to format the unordered list in the sidebar <div>
  • A selector to format the first news teaser.

You don't need to actually change any properties; I just want the selectors.

Creative © 2007 Calvin College and Jeremy D. Frens.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.