Chapter 7. Getting Started with CSS: Adding a Little Style

  • CSS contains simple statements, called rules.
  • A typical rule consists of a selector(选择器) along with one or more properties(属性) and values(值).
  • Each property declaration ends with a ; (semicolon).
  • All properties and values in a rule go between { } (braces).
  • By separating element names with , (commas), you can select multiple elements at once.
  • Use .classname to select any elements that belong to the class.
  • You can specify that an element belongs to more than one class by placing multiple class names in the class attribute with spaces between the names.

  • Not every style is inherited. Just some are, like font-family.
  • The <a> and <em> elements inherited the font-family style from the <p> element, which is their parent element.
  • To write a comment in your CSS, just enclose it between /* and */.
    • e.g. /* this rule selects all paragraphs and colors them blue */
  • Use the class attribute to add elements to a class. Elements can be in more than one class.
  • W3C CSS validator

<link type="text/css" rel="stylesheet" href="../lounge.css">



body {
        font-family: sans-serif;
}

h1, h2 {
        color: gray;
}

h1 {
        border-bottom: 1px solid black;
}

p {
        color: maroon;
}

p.greentea {
        color: green;
}

p.raspberry {
        color: blue;
}

p.blueberry {
        color: purple;
}



Word list

  • solid
  • crucial
  • brace
  • commas
  • elixir
  • blown
  • override
  • inheritance
  • the hang of

<
Previous Post
0901 Reading, learning, and August summary
>
Next Post
0902 Learning, reading, and looking for interesting things