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

My digital project (2): the style file

الأسبوع 11 · الدرس ٣ «مشروعي الرقمي لمدرستي» (٢): كود CSS لتنسيق الصفحتين وشرحه · 3 دروس
3

Read the code, fix the mistake, improve it

ICT Prep 2 Term 1, Unit 2, Lesson 3: pp. 70–72
GoalFind a mistake in short code, predict the look and make two changes.
New words
error (bug) · a mistake in code that makes it work wrongly or not at allpredict · to say what will happen before it happensclass name · the name that must match in the HTML and in the CSScurly brace · the symbols { and } that open and close a rule
Explanation

Programmers read code like detectives. In a code clinic you look for the mistake before anything else. Four common ones: a missing semicolon at the end of a line, a colour name written with a space, a missing closing brace, and a class name that does not match. In the pictures, the first rule writes dark blue with a space, so the colour is not understood. The second forgets the semicolon after white, so the next line may stop working. In the third, the HTML says container but the CSS says contanier, so the rule never reaches the box. Once the code is correct, you can predict: if width changes from 80% to 60%, the box becomes narrower; if darkblue becomes darkgreen, the bar becomes green. Remember Week 9: one change in the style file changes every page.

MistakeFix
colour with a space: dark bluewrite it as darkblue
missing semicolon after whiteadd the semicolon
missing closing braceadd the closing brace
class name does not matchuse the same name in HTML and CSS
Worked examples
Css
1header {
2  background-color: dark blue;
3  color: white;
4}
Code clinic one: header { background-color: dark blue; color: white; }. The mistake is the space in dark blue. The fixed rule uses darkblue. Clinic two: footer { color: white padding: 15px; } needs a semicolon after white.
Css
1.contanier {
2  width: 80%;
3}
Clinic three: the HTML box is class container, but the CSS rule starts with .contanier. The names do not match, so the width rule never reaches the box. The fix: spell the class name the same way in both files.
Class activity

Write a code clinic of your own: invent a rule with one deliberate mistake and swap it with a classmate to find it. Then change two values in a correct rule and write what the page will look like after each change. No device is needed.

Practice
1
Name two common mistakes in CSS.
2
In the clinic, why does .contanier not style the box?
3
Predict: width changes from 80% to 60%. What happens to the box?
4
Why does one change in the style file change both pages?