Chapter III
Chapter III
prepared by Suleyman Y.
CSS
2
prepared by Suleyman Y.
CSS Cont…
4
prepared by Suleyman Y.
CSS….
6
prepared by Suleyman Y.
CSS….
7
prepared by Suleyman Y.
CSS…
8
prepared by Suleyman Y.
CSS…
9
prepared by Suleyman Y.
Basic CSS rule syntax
10
selector {
property: value;
property: value;……
property: value;
}
Example
p {
font-family: sans-serif;
color: red;
}
prepared by Suleyman Y.
CSS Rules….
11
prepared by Suleyman Y.
Attaching a CSS file <link>
12
<head>
<link href="filename
"type="text/css"
rel="stylesheet" />
</head>
prepared by Suleyman Y.
CSS Cont…
13
h1 is an html tag used as
selector and
{font-size: 12px; color: red;}
this is Declaration where
font-size and color are
properties where 12px and
red are their respective values
prepared by Suleyman Y.
CSS Cont…
14
prepared by Suleyman Y.
CSS ID Selector…..
20
prepared by Suleyman Y.
CSS Class Selector…
21
Example
<h2 class=”center”>Summary</h2>
We can then create a CSS rule with the class
selector:
.center
{
text-align: center;
font-size:16px;
}
prepared by Suleyman Y.
CSS class Selector…
22
Though all the elements in a class are
affected by the style
We can also specify the elements to be
affected by the style in the class using
the specific element with the class
Example
p.center {text-align:center;}
Here we are affecting only the
paragraph element in the class center
prepared by Suleyman Y.
CSS Comments
23
prepared by Suleyman Y.
Types of CSS
27
Internal(Document level)
External imported
Example
<head>
<link rel="stylesheet" type="text/css"
href="mystyle.css" />
</head>
CSS Has file extension .css
Multiple external style can be
specified for a single html document
prepared by Suleyman Y.
External CSS….
30
prepared by Suleyman Y.
External CSS….
31
NB. Do not leave spaces between
the property value and the units
As margin-left:20 px;
instead of margin-left:20px;
It may not work for most of
currently used web browsers.
Like Firefox and others
prepared by Suleyman Y.
Internal Style Sheet
32
prepared by Suleyman Y.
Internal CSS…
33
Example
<head>
<style type="text/css">
hr {color:sienna;}
p {margin-left:20px;}
Body
{background-image:url("images/back4
0.gif");}
</style> </head>
prepared by Suleyman Y.
Inline CSS…
34
prepared by Suleyman Y.
Cascading Order
35
Background properties
background-color
background-image
background-repeat
background-attachment
background-position
prepared by Suleyman Y.
CSS Properties….
39
Background-image:
To display an image on the background of
the page
The image fills the elements content area
Example
body{background-image:
url("images/draft.jpg");
background-repeat: repeat-x;
}
prepared by Suleyman Y.
CSS Properties….
40
Background-repeat:
can be:
repeat (default),
repeat-x,
repeat-y,
or no-repeat
prepared by Suleyman Y.
CSS Properties….
41
Background-position
value consists of two tokens,
each of which can be top, left,
right, bottom, center, a
percentage, or a length value in
px, pt, etc.
value can be negative to shift
left/up by a given amount
prepared by Suleyman Y.
CSS Properties…
42
Example:
body {background-image:
url("images/draft.jpg");
background-repeat: no-repeat;
background-position: 370px
20px;
}
prepared by Suleyman Y.
CSS Properties cont…
43
Color Properties
Text –color:
Background-color:
Example
p {
color: red;
background-color: yellow;
}
prepared by Suleyman Y.
CSS Properties cont…
44
Font Properties
Font-size: how large the letters will be
drawn
Font-family: which font will be
used
font-style: used to enable/disable
italic style
font-weight :used to enable/disable
bold style
prepared by Suleyman Y.
CSS Properties cont…
45
Example
p {
font-family: Georgia;
}
h2 {
font-family: "Courier New";
}
prepared by Suleyman Y.
CSS Properties…
46
We can specify multiple fonts from
highest to lowest priority
Generic font names:
serif, sans-serif, cursive, fantasy,
monospace
If the first font is not found on the
user's computer, the next is tried
prepared by Suleyman Y.
CSS Properties…
47
Font-Size:
Specify the size of the text
Has different units
pt specifies number of point, where a
point is 1/72 of an inch on screen
px specifies a number of pixels on the
screen
em specifies number of m-widths,
Line Height
Height of line box given by
line-height
Initial
value: normal (i.e., cell
height; relationship with em
height is font-specific)
Other values (following are
equivalent):
prepared by Suleyman Y.
CSS Properties….
50
prepared by Suleyman Y.
CSS Properties…
51
property description
alignment of text within its
text-align
element
decorations such as
text-decoration
underlining
line-height,
gaps between the various
word-spacing,
portions of the text
letter-spacing
indents the first letter of each
text-indent
paragraph
text-align can be left, right,
center, or justify
prepared by Suleyman Y.
CSS Properties….
53
Color Properties
Font color specified by color
property
Two primary ways of specifying
colors:
Color name: black, gray, silver, white,
red, lime, blue, yellow, aqua, fuchsia,
maroon, green, navy, olive, teal, purple
RGB values
prepared by Suleyman Y.
Alternative formats for colors
56
prepared by Suleyman Y.
CSS Properties….
57
The list-style-type property:
to list things in the order of roman numbers like:
i. none : No marker
ii. disc (default), circle, square
iii. Decimal: 1, 2, 3, etc.
iv. decimal-leading-zero: 01, 02, 03, etc.
v. lower-roman: i, ii, iii, iv, v, etc.
vi. upper-roman: I, II, III, IV, V, etc.
vii. lower-alpha: a, b, c, d, e, etc.
viii. upper-alpha: A, B, C, D, E, etc.
x. lower-greek: alpha, beta, gamma, etc.
prepared by Suleyman Y.
CSS Properties….
58
Example
Ol
{
list-style-type: lower-roman;
}
ul
{
list-style-type: square;
}
prepared by Suleyman Y.
CSS Properties….
59
element
Examples
body {
font-size: 16px;
font-weight: bold;
font-style: italic;
}
prepared by Suleyman Y.
CSS Properties….
60
prepared by Suleyman Y.
External CSS Practices…
61
prepared by Suleyman Y.
External CSS Practices…
62
<html>
<head>
<title>Style Example</title>
<link rel="stylesheet"
type="text/css" href="style.css">
</head>
<p class="excerpt">affected
text</p>
</html>
prepared by Suleyman Y.
CSS Box Model
63
prepared by Suleyman Y.
CSS Box Model
64
prepared by Suleyman Y.
CSS Box Model
65
prepared by Suleyman Y.
Normal Flow Layout
66
of parent
Sibling block elements are laid out one on top
of the other
Sibling inline elements are one after the other
prepared by Suleyman Y.
Normal Flow Layout
67
prepared by Suleyman Y.
Normal Flow Layout
68
prepared by Suleyman Y.
Normal Flow Layout
69
<span style="background-
color:red">
span </span><span class="right">Red</span>
containin
g
text
moves
left
prepared by Suleyman Y.
Beyond Normal Flow….
71
Float positioning:
prepared by Suleyman Y.
Beyond Normal Flow….
72
Absolute Positioning:
span’s removed
from
normal flow and
positioned relative
to another box
prepared by Suleyman Y.
Beyond Normal Flow Layout
73
prepared by Suleyman Y.