css ppt
css ppt
CS380
Cascading Style Sheets (CSS)
2
CS380
CSS ...
3
CS380
How to write CSS?
4
Selector
HTML element tags
(examples: p, h2, body, img, table)
class and ID names
CS380
How to write CSS?
5
Example:
p {font-size: 8pt; color: red}
CS380
CSS Selectors
7
p{
text-align: center;
color: red;
}
CS380
CSS Selectors
8
The id Selector
The id selector uses the id attribute of an HTML
element to select a specific element.
The id of an element should be unique within a
page, so the id selector is used to select one unique
element!
To select an element with a specific id, write a hash
(#) character, followed by the id of the element.
CS380
CSS Selectors
9
Example:
<!DOCTYPE html>
<html><head><style>
#para1 { text-align: center; color: red;}
</style></head><body>
<p id="para1">Hello World!</p>
<p>This paragraph is not affected by the
style.</p>
</body>
CSS Selectors
10
CS380
CSS Selectors
11
Example:
<style>
.center { text-align: center; color: red; }
</style>
<body>
<h1 class="center">Red and center-aligned
heading</h1>
<p class="center">Red and center-aligned
paragraph.</p>
CS380
CSS Selectors
12
Grouping Selectors:
h1 {
text-align: center;
color: red;
}
h2 {
text-align: center;
color: red;}
p {text-align: center;color: red;}
CS380
Modifying CSS styles
13
h2 {font-family : Tahoma;
color: blue;
text-align: center;
text-transform :
uppercase;
}
body {font-family : Courier
New;background-color :
#FFEEDD;color : #777733;
}
Basic CSS rule syntax
14
selector {
property: value;
property: value;
...
property: value;
} CSS
p {
font-family: sans-serif;
color: red;
} CSS
<head>
...
<link href="filename" type="text/css" rel="stylesheet" />
...
</head> HTML
CS380
Embedding style sheets: <style>
16
<head>
<style type="text/css">
p { font-family: sans-serif; color: red; }
h2 { background-color: yellow; }
</style>
</head>
HTML
CS380
Inline styles: the style attribute
17
HTML
This is a paragraph
output
CS380
CSS properties for colors
18
p {
color: red;
background-color: yellow;
}
CSS
property description
color color of the element's text
color that will appear behind the
background-color
element
CS380
Specifying colors
19
p { color: red; }
h2 { color: rgb(128, 0, 196); }
h4 { color: #FF8800; }
CSS
color names: aqua, black, blue, fuchsia, gray, green, lime, maroon,
navy, olive, purple, red, silver, teal, white (white), yellow
RGB codes: red, green, and blue values from 0 (none) to 255 (full)
hex codes: RGB values in base-16 from 00 (0, none) to FF (255, full)
Grouping styles
20
p, h1, h2 {
color: green;
}
h2 {
background-color: yellow;
} CSS
CS380
CSS comments /*…*/
21
/* This is a comment.
It can span many lines in the CSS file. */
p {
color: red; background-color: aqua;
} CSS
CS380
CSS properties for fonts
22
property description
font-family which font will be used
font-size how large the letters will be drawn
font-style used to enable/disable italic style
font-weight used to enable/disable bold style
CS380
font-family
23
p {
font-family: Georgia;
}
h2 {
font-family: "Courier New";
} CSS
CS380
More about font-family
24
p {
font-family: Garamond, "Times New Roman", serif;
} CSS
p {
font-size: 24pt;
} CSS
CS380
font-size
26
p {
font-size: 24pt;
} CSS
CS380
font-weight, font-style
27
p {
font-weight: bold;
font-style: italic;
} CSS
Either of the above can be set to normal to turn them off (e.g.
headings)
CS380
CSS properties for text
28
property description
text-align alignment of text within its element
text-decoration decorations such as underlining
line-height,
gaps between the various portions of
word-spacing,
the text
letter-spacing
indents the first letter of each
text-indent
paragraph
CS380
text-align
29
We wants it, we needs it. Must have the precious. They stole it from us.
Sneaky little hobbitses. Wicked, tricksy, false!
output
CS380
text-decoration
30
p {
text-decoration: underline;
} CSS
CS380
The list-style-type property
31
ol { list-style-type: lower-roman; }
CSS
Possible values:
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.
CS380
others: hebrew, armenian, georgian, cjk-ideographic, hiragana…
Body styles
32
body {
font-size: 16px;
}
CSS
CS380
Cascading Style Sheets
33
CS380
Cascading Style Sheets
34
CS380
Cascading Style Sheets
35
CS380
Cascading Style Sheets
36
CS380
Cascading Style Sheets
37
CS380
Cascading Style Sheets
38
CS380
Inheriting styles
40
This is a heading
A styled paragraph. Previous slides are available on the website.
when two styles set conflicting values for the same property,
the latter style takes precedence
CS380
W3C CSS Validator
42
<p>
<a href="http://jigsaw.w3.org/css-
validator/check/referer">
<img src="http://jigsaw.w3.org/css-validator/images/vcss"
alt="Valid CSS!" /></a>
</p> CSS
output
jigsaw.w3.org/css-validator/
checks your CSS to make sure it meets the official CSS
specifications
CS380
CSS properties for backgrounds
43
property description
background-color color to fill background
background-image image to place in background
background-position placement of bg image within element
whether/how bg image should be
background-repeat
repeated
background-attachment whether bg image scrolls with page
shorthand to set all background
background
properties
CS380
background-image
44
body {
background-image: url("images/draft.jpg");
}
CSS
CS380
background-repeat
45
body {
background-image: url("images/draft.jpg");
background-repeat: repeat-x;
}
CSS
CS380
background-position
46
body {
background-image: url("images/draft.jpg");
background-repeat: no-repeat;
background-position: 370px 20px;
} CSS
The link tag, placed in the HTML page's head section, can
specify an icon
this icon will be placed in the browser title bar and bookmark/favorite
CS380