A basic CSS rule has the following format:
selector {
property: value;
}
Each property and value set are called a declaration.
selector {
property: value;
}
You can list as many declarations as you want. A group of declarations are called a declaration block.
selector { property: value;
property: value;}
Things to note:
You type comments in to your CSS by using ( /*
) and ( */
). Comments can span multiple lines.
/* A CSS comment */
/* A
Comment in
multiple lines
*/
The most basic CSS selectors are Element Type Selectors. These are really just HTML tags.
For example, if we wanted to make all paragraphs have red text, we would use the following CSS rule:
p {
color: red;
}
If we wanted to make all of the ordered lists and unordered lists red, in addition to the paragraphs, we could use three rules like this:
p {
color: red;
}
ol {
color: red;
}
ul {
color: red;
}
Better yet, we can combine these three rules, by listing the selectors, separated by commas.
p, ol, ul {
color: red;
}