Lesson 2 / الدرس 2
Syntax: selector, property, value / الصياغة: المُحدِّد والخاصية والقيمة
Every CSS rule has the same shape: a selector says which elements it targets, and one or more declarations — each a property paired with a value — say how they should look.
لكل قاعدة CSS نفس الشكل: مُحدِّد يقول أي العناصر يستهدف، وإعلان واحد أو أكثر — كل إعلان خاصية مقترنة بقيمة — يقول كيف يجب أن تبدو.
Every rule you will ever write in CSS, simple or complicated, has exactly the same shape. Learn to name its pieces once, and every stylesheet you read afterward — yours or anyone else's — becomes readable.
p {
color: navy;
}
The selector: which elements
p is the selector. It picks which elements the rule applies to — here, every <p> on the page. There are many kinds of selector, and a bare tag name like this is the simplest one there is.
p هنا هو المُحدِّد. وهو يحدد العناصر التي تنطبق عليها القاعدة؛ وهنا كل <p> في الصفحة. وستقابل أنواعًا كثيرة من المُحدِّدات لاحقًا، وأبسطها هو اسم وسم مجرّد كهذا.The declaration: property + value
Between the braces sits color: navy; — one declaration. Split it in two: color is the property, the aspect of the element you are changing, and navy is the value, the setting you are giving it. A colon separates them, and a semicolon ends the declaration. A rule can hold as many declarations as it needs, one after another.
color: navy; — وهذا إعلان واحد. اقسمه إلى جزأين: color هي الخاصية، أي جانب العنصر الذي تغيّره، و navy هي القيمة، أي الإعداد الذي تعطيه له. وتفصل بينهما نقطتان رأسيتان، وينتهي الإعلان بفاصلة منقوطة. وتستطيع القاعدة أن تحمل عدد الإعلانات الذي تحتاجه، واحدًا تلو الآخر.p {
color: navy;
font-size: 1.2rem;
text-align: center;
}
| Term | Example | Meaning |
|---|---|---|
| Selector | p | Which elements the rule applies to |
| Property | color | The aspect being changed |
| Value | navy | The setting given to the property |
| Declaration | color: navy; | One property + one value together |
| Rule | p { color: navy; } | A selector plus its declarations |
Every term from this lesson, side by side.
Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1.
In h1 { color: navy; }, which word is the property?
h1 { color: navy; } أي كلمة هي الخاصية؟color is the property — the aspect of the element being changed. h1 is the selector and navy is the value.
color هي الخاصية — أي جانب العنصر الذي يتغيّر. أما h1 فهو المُحدِّد، و navy هي القيمة.2. Which word in that same rule is the selector?
h1 comes before the opening brace and says which elements the rule targets — every <h1> on the page.
h1 قبل القوس المفتوح، وتحدد العناصر التي تستهدفها القاعدة — كل <h1> في الصفحة.
3.
color: navy; together — what is this called?
color: navy; معًا — ماذا يُسمّى هذا؟A property paired with a value, ending in a semicolon, is a declaration. A rule is the whole thing — the selector plus its braces and every declaration inside them.
Score / النتيجة: 0 / 3
Your task / مهمتك
Write a rule that targets every <h2> and gives it two declarations: a color and a font-size. Then write a second rule for every <p> with at least one declaration of your choice.
اكتب قاعدة تستهدف كل <h2> وتمنحها إعلانين: color و font-size. ثم اكتب قاعدة ثانية لكل <p> بإعلان واحد على الأقل من اختيارك.
- A rule with the selector h2 قاعدة بالمُحدِّد h2
- The h2 rule has at least two declarations, each ending with a semicolon قاعدة h2 فيها إعلانان على الأقل، كل واحد ينتهي بفاصلة منقوطة
- A separate rule targets p قاعدة مستقلة تستهدف p