M03 CSS
M03 CSS
Module Number: 03
Version Code:WTF6
Released Date:24-Jan-2019 1
CSS
AIM:
2
CSS
Objectives:
3
CSS
Outcome:
4
CSS
Contents
1. Introduction to CSS
2. Syntax
3. Selectors
4. Embedding CSS to Html
5. Formatting fonts
6. Text and background colour
7. Borders and boxing
5
CSS
Introduction to CSS
• CSS stands for Cascading Style Sheets.
• CSS describes how HTML elements are to be displayed on screen, paper or in other media.
• CSS saves a lot of work. It can control the layout of multiple web pages all at once.
6
CSS
Introduction
CSS Timeline
CSS3(1999)
CSS2(1998)
CSS1(1996)
8
CSS
Document Links
Topics URL
https://www.w3schools.com/css/css_intro.asp
Introduction to CSS
9
CSS
Video Links
Topics URL
Introduction to CSS https://www.youtube.com/watch?v=qKoajPPWpmo
Introduction to CSS https://www.youtube.com/watch?v=lNEp3qv2lO8
10
CSS
11
CSS
12
CSS
a. 1996
b. 1994
c. 1995
d. 1992
Answer: 1996
13
CSS
a. 1998
b. 2000
c. 1999
d. 2001
Answer: 1998
14
CSS
CSS Syntax
15
CSS
CSS Syntax
A CSS rule-set consists of a selector and a declaration block:
Document Links
Topics URL
17
CSS
Video Links
Topics URL
18
CSS
5. There can be more than one declaration in a CSS rule set separated by a semicolon. State whether
True or False.
a. True
b. False
Answer: True
19
CSS
a. Declaration
c. Selector
20
CSS
CSS Selectors
21
CSS
CSS Selectors
Element selector
Selector
ID selector
Class selector
22
CSS
Element Selector
Example A:
h2 {
colour: blue;
background-colour: lightblue;
}
Example B:
p{
colour: red;
background-colour: yellow;
}
23
CSS
ID Selector
#para1 {
text-align: center;
colour: red;
}
<p id=“para1”>
Hello World!
<p>
24
CSS
Class Selector
Example A
.center {
text-align: center;
colour: red;
}
Example B
p.center {
text-align: center;
colour: red;
}
25
CSS
Document Links
Topics URL
26
CSS
Video Links
Topics URL
Selectors https://www.youtube.com/watch?v=KZ7h5DZ-vL0
27
CSS
c. Both A and B
28
CSS
a. # character
b. $ character
c. & character
Answer: # character
29
CSS
9. We can use the same id for more than one element on a page. State whether True or False.
a. True
b. False
Answer: False
30
CSS
10. Class selector allows us to style only specific elements of an element type. State whether True or
False.
a. True
b. False
Answer: True
31
CSS
32
CSS
33
CSS
Inline Style
34
CSS
<head>
<style>
body
{
background colour: powderblue;
}
h1
{
colour: maroon;
margin-left: 40px;
}
</style>
</head>
35
CSS
<head>
<link rel="stylesheet" type="text/css" href=“filename.css">
</head>
36
CSS
body
{
background-colour: lightblue;
}
h1
{
colour: navy;
margin-left: 20px;
}
37
CSS
Document Links
Topics URL
https://www.w3schools.com/html/html_css.asp
HTML Styles- CSS
https://matthewjamestaylor.com/add-css-to-html
How to Embed CSS to HTML
38
CSS
Video Links
Topics URL
https://www.w3schools.com/html/html5_video.asp
Embed CSS to HTML
39
CSS
a. Body: colour=black
b. {body; colour: black}
c. {body: colour= black(body}
d. body {colour: black}
40
CSS
12. Including the style element in the head section is called _______ style.
41
CSS
13. Inline style uses ______________ attribute to define the style of an element.
a. Head
b. Background
c. Style
Answer: Style
42
CSS
43
CSS
Formatting Fonts
44
CSS
CSS Fonts
The CSS font properties define:
• font family
• weight
• Size
• Style
• Font-variant
of a text.
45
CSS
Font Families
Font family
Generic family
Example: Times
Example : Serif
New Roman
46
CSS
47
CSS
48
CSS
49
CSS
The font-size property sets the size of the text. The font size can be set using pixels, em or a combination
of both.
Example A: using pixels
h1 {
font-size: 40px;
}
Example B: using em unit (1 em unit = current font size)
h1 {
font-size: 2.5em; /* 40px/16=2.5em */
}
50
CSS
51
CSS
CSS ICONS
The simplest way to add an icon to your HTML page is with an icon library, such as Font Awesome.
52
CSS
To use the Font Awesome icons, add the following line inside the <head> section of your
HTML page:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/4.7.0/css/font-awesome.min.css">
53
CSS
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflar
e.com/ajax/libs/font-awesome/4.7.0/css/font-
awesome.min.css">
</head>
<body>
<i class="fa fa-cloud"></i>
<i class="fa fa-heart"></i>
<i class="fa fa-car"></i>
<i class="fa fa-file"></i>
<i class="fa fa-bars"></i>
</body>
54
</html>
CSS
Document Links
Topics URL
https://www.w3schools.com/css/css_font.asp
CSS Fonts
https://www.w3schools.com/csSref/pr_font_font.asp
Font Property
Fundamental Text
https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals
and Font Styling
55
CSS
Video Links
Topics URL
https://www.youtube.com/watch?v=yBSK-B65XyQ
Style font in CSS
56
CSS
a. Sans Serif
b. Times
c. Calibri
d. None of the above
57
CSS
a. 200
b. 400
c. 800
d. 100
Answer: 400
58
CSS
17. The font-style property is mostly used to specify which text style.
a. Normal
b. Oblique
c. Italic
d. None of the above
Answer: Italic
59
CSS
60
CSS
Text colour
The colour property is used to set the colour of the text. The colour is specified by:
The default text colour for a page is defined in the body selector.
61
CSS
Example
body {
colour: blue;
}
h1 {
colour: green;
}
62
CSS
Background colour
• The background-colour property specifies the background colour of an element.
For Example,
body {
background-colour: light blue;
}
Document Link
Topics Links
CSS Background https://www.w3schools.com/csSref/pr_background-color.asp
64
CSS
Video Link
Topics URL
65
CSS
18. The default text colour for a page is defined in the body selector. State whether True or False.
a. True
b. False
Answer: True
66
CSS
67
CSS
68
CSS
CSS Borders
69
CSS
Example
<style>
.borderStyling {
border-style: dotted;
border-colour: blue;
border-width: 3px;
border-radius: 10px;
}
</style>
70
CSS
71
CSS
72
CSS
Box Dimensions
73
CSS
Box Dimensions
Border
The border starts at the outer edge of the padding.
By default, there is no border or border size 0.
example: border:2px, solid black
2 pixels thick solid black border.
Border can also be set all four at once using the border property or individually using
– border-top
– border-right
– border-bottom
– border-left.
Box Dimensions
Margin
The margin surrounds the CSS box and lies between the boxes.
The margin width can be set all at one using the margin property or individually using the margin-top,
margin-right, margin-bottom and margin-left properties.
Example dimensions for a paragraph element:
p{
width: 300px;
border: 25px solid green;
padding: 25px;
margin: 25px;
}
The width is 300 px, padding and margin are 25px, and the border is 25px solid and green in colour.
75
CSS
Box Dimensions
Margin collapsing
When two CSS boxes touch against one another in a webpage, the distance between them will be the
value of the largest of the two margins, and not their sum.
76
CSS
Document Links
Topics Links
77
CSS
Video Links
Topics URL
78
CSS
a. Inset
b. Groove
c. Ridge
d. Outcast
a. The margin between the outer edge of the border and outer edge of the content box.
b. The inner margin between the inner edge of the border and the outer edge of the content box.
c. Both A and B
Answer: The inner margin between the inner edge of the border and the outer edge of the
content box
80
CSS
a. The margin
b. The border
c. The Line
81
CSS
23. CSS displays each element in a box format. State whether True or False.
a. True
b. False
Answer: True
82
CSS
Assignment
2. How can you embed an HTML page in CSS? Explain with example.
4. Assume multiple elements have class="btn red". What CSS selector should we use to style only
elements that have both of these classes?
5. What CSS selector should you use to style all <input type="button"> elements with class="btn"?
Summary
• CSS describes how HTML elements are to be displayed on a screen, paper or in other media.
• CSS saves a lot of work. It can control the layout of multiple web pages all at once.
• A CSS declaration always ends with a semicolon, and declaration blocks are surrounded by curly
braces.
• In the Text colour, the default text colour for a page is defined in the body selector.
84
CSS
Summary (Cont…)
• The border starts at the outer edge of the padding.
• The margin width can be set all at one using the margin property or individually using the margin-
top, margin-right, margin-bottom and margin-left properties.
85
CSS
Document Links
Topics URL
Introduction to CSS https://www.w3schools.com/css/css_intro.asp
86
CSS
Document Links
Topics URL
CSS Fonts https://www.w3schools.com/css/css_font.asp
Font Property https://www.w3schools.com/csSref/pr_font_font.asp
Fundamental Text and
https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals
Font Styling
CSS Background https://www.w3schools.com/csSref/pr_background-color.asp
CSS Text https://www.w3schools.com/css/css_text.asp
CSS box-sizing
https://www.w3schools.com/csSref/css3_pr_box-sizing.asp
property in CSS
CSS Box Model https://www.w3schools.com/css/css_boxmodel.asp
87
CSS
Video Links
Topics URL
Introduction to CSS https://www.youtube.com/watch?v=qKoajPPWpmo
Introduction to CSS https://www.youtube.com/watch?v=lNEp3qv2lO8
CSS Syntax https://www.youtube.com/watch?v=QqmCs2UTS8s
Introduction to CSS Selectors https://www.youtube.com/watch?v=EeZKHmNJipE
Selectors https://www.youtube.com/watch?v=KZ7h5DZ-vL0
Embed CSS to HTML https://www.youtube.com/watch?v=jpjzhva3owA
Embedding CSS to HTML https://www.youtube.com/watch?v=7AEFciYWquY
Style font in CSS https://www.youtube.com/watch?v=yBSK-B65XyQ
88
CSS
Video Links
Topics URL
Changing font colour, size and type https://www.youtube.com/watch?v=UO0ZPL8yMpU
Background colour https://www.youtube.com/watch?v=-Ss7VdgJQ1I
Font and background colour https://www.youtube.com/watch?v=rOzvtFetv8A
Box Sizing in CSS https://www.youtube.com/watch?v=Nk8CZuH7C8k
CSS Box Model https://www.youtube.com/watch?v=qhiQGPtD1PQ
89
CSS
E-Book Links
https://goalkicker.com/CSSBook/C
CSS Backgrounds and Boarders 22-38, 63-68
SSNotesForProfessionals.pdf
90