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

My digital project (2): the style file

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

Spacing, borders and centring

ICT Prep 2 Term 1, Unit 2, Lesson 3: pp. 70–72
GoalTell padding from margin and read the rules for width, centring and borders.
New words
padding · space inside a box, between its content and its bordermargin · space outside a box, between it and other thingsborder · the line around a box, or one side of itwidth · how wide a box is; 80% means a share of the page width
Explanation

Every box has four layers, from the inside out: the content, the padding, the border and the margin. Padding is the space inside the box, between the content and the border. Margin is the space outside the box, between it and its neighbours. Do not mix them up. In our style file, the container has width: 80%, a share of the page width, and margin: auto, which gives equal space on both sides so the box sits in the centre. Each section has padding: 10px, a very small step on the screen, so text does not touch the edges. A sub-heading h2 has border-bottom, a line under it. A thick line under a sub-heading helps the eye to find a new part.

A
1margin: space outside the box
2border: the line around it
3padding: space inside, around the content
4content: the words
Worked examples
Css
1.container {
2  width: 80%;
3  margin: auto;
4  background-color: lightcyan;
5}
6section {
7  padding: 10px;
8}
9h2 {
10  border-bottom: 3px solid darkblue;
11}
Read the picture. container: width 80% and margin auto, so the box is 80% wide and centred. section: padding 10px, so the words keep a little room from the edges. h2: border-bottom 3px solid darkblue, a dark blue line under the sub-heading.
PropertyWhere the space is
paddinginside the box
marginoutside the box
A student says “padding is the space between two boxes.” Her teacher corrects her: that is margin. Padding is the space inside a box, between the content and its border. A small drawing of a box in a box shows the difference.
Class activity

Draw a box inside a box on paper. Label the content, the padding, the border and the margin. Then write the three lines of CSS from the container rule, and say in your own words what each one does.

Practice
1
A box has a gap between its words and its border. Is that gap padding or margin?
2
A box has a gap between its border and the next box. Is that gap padding or margin?
3
What does margin: auto do for a box with a width?
4
What does border-bottom do to an h2?