0902 Head First HTML and CSS — Study Log #6
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 moreproperties(属性)andvalues(值). - Each property declaration ends with a
;(semicolon). - All properties and values in a rule go between
{ }(braces). - By separating
elementnames with,(commas), you can select multipleelementsat once. - Use
.classnameto select anyelementsthat belong to theclass. -
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 thefont-familystyle 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 */
- e.g.
- Use the
classattribute to addelementsto a class.Elementscan be in more than oneclass. - 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