☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

CSS: the looks of a web page

الأسبوع 9 · الدرس ٢ «تنسيق صفحات الويب»: لغة CSS وفوائدها وبنيتها وطرق إضافتها وملف CSS خارجي · 3 دروس
2

Selector, property, value

ICT Prep 2 Term 1, Unit 2, Lesson 2: pp. 56–62
GoalRead a CSS rule and name its selector, property and value.
New words
selector · the part of the page that the rule talks about, such as h1 or pproperty · what you want to change, such as colour or font sizevalue · how you want it changed, such as darkblue or 18pxrule · one complete instruction: selector, then property and value in curly brackets
Explanation

A CSS rule has a fixed shape: selector { property: value; }. The selector says which part of the page, the property says what to change, and the value says how. Between the curly brackets we write the property, a colon, the value and a semicolon. Look at the three rules in the picture. The first says that every h1 heading (selector h1) gets dark blue text (property color, value darkblue) and is centred. The second says that every paragraph gets letters of size 18px (px means pixels, tiny dots on the screen). The third gives the whole page (body) a very pale blue-green background. Colour names have no spaces: lightcyan is correct and light blue is not. Always finish each line with a semicolon.

Css
1h1 {
2  color: darkblue;
3  text-align: center;
4}
5p {
6  font-size: 18px;
7}
8body {
9  background-color: lightcyan;
10}
Worked examples
SelectorPropertyValue
h1colordarkblue
h1text-aligncenter
Read the first rule aloud: “For every h1, set the color to darkblue and the text-align to center.” The selector is h1. The properties are color and text-align. The values are darkblue and center.
Css
1p {
2  font-size: 18px;
3  color: black;
4}
Nour writes the two lines font-size: 18px and color: black one under the other but forgets the semicolon after 18px, so the browser cannot tell where the first line ends and ignores both lines. A semicolon ends each line inside the brackets. She adds it and everything works.
Class activity

Write your own three CSS rules on paper for an invented page: one for h1, one for p and one for body. For each rule, underline the selector, circle the property and put a box around the value. Use only colour names without spaces.

Practice
1
In h1 { color: red; }, which part is the selector?
2
In the same rule, name the property and the value.
3
What goes at the end of each line inside the curly brackets?
4
Which is correct, lightblue or light blue?