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

CSS: the looks of a web page

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

One style file for many pages

ICT Prep 2 Term 1, Unit 2, Lesson 2: pp. 56–62
GoalShow how one style file formats two pages and predict a change.
New words
inline CSS · a rule written inside one element, only for that elementinternal CSS · rules written in the head of one page, only for that pageexternal CSS · rules kept in a separate file that many pages link tolink · the line in the head that connects a page to its style file
Explanation

There are three ways to add CSS. Inline CSS is written inside one element and only changes that element. Internal CSS sits in the head of one page and only changes that page. External CSS lives in a separate file with the ending .css, and many pages can link to it, so it is best for a whole site. The link line goes in the head: the part href gives the file name, and rel="stylesheet" says what kind of file it is. Look at the two pages in the pictures. Both link to the same style file. So both headings are dark green and both paragraphs use letters of size 18px. If you change one value in the style file, both pages change at once, which is the benefit “edit once, every page follows” from Lesson 1.

WayWhere it is writtenCovers
inlineinside one elementthat element only
internalin the head of a pagethat one page
externalin a separate .css fileevery page that links to it
Worked examples
Html
1<html>
2<head>
3  <link rel="stylesheet" href="style.css">
4</head>
5<body>
6  <h1>Class garden diary</h1>
7  <p>We planted beans today.</p>
8</body>
9</html>
Page one is the class garden diary and page two is the pets of the class. Both pages have the same link line. The style file says that h1 is dark green and p has size 18px. So both pages get the same look.
Css
1h1 {
2  color: darkgreen;
3}
4p {
5  font-size: 18px;
6}
7
The shared file is style.css. Page two has the same link line; only its heading and paragraph words differ (“Pets of the class”, “Our class loves cats”). Prediction task: if the value darkgreen is changed to darkred in style.css, what happens? Both headings turn dark red, because both pages link to the same file.
Class activity

On paper, copy the style file and change one value. Then draw how page one and page two look before and after. Write one sentence that begins “Because both pages link to the same file…”. No device is needed.

Practice
1
Which kind of CSS is best for a large site and why?
2
What does the link line in the head do?
3
In the link line, what is href and what is rel="stylesheet"?
4
Prediction: both pages link to style.css. One value changes. How many pages change?