CSS Training
CSS Training
<p>
<font face="Arial">Shashdot.</font>
News for <b>nerds!!</b> You will <i>never</i>, <u>EVER</u>
be
<font size="+4" color="red">BORED</font> here!
</p> HTML
CS380
Basic CSS rule syntax
4
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
<head>
<style type="text/css">
p { font-family: sans-serif; color: red; }
h2 { background-color: yellow; }
</style>
</head>
HTML
This is a paragraph
output
<h1>Fancy Lads</h1>
<p>Welcome to The Fancy lad Site!</p>
<p>This web-page is the semi-official home of Fancy lads on the
World Wide Web.</p>
<p align="center">
<font face="Papyrus"><img border="0" src=“fancy-header.png”
width="207" height="279"></font>
</p>
<p align="center">
<font face="Papyrus“> Welcome to The Fancy lad Site!</font>
</p>
<p align="center">
<font face="Papyrus">This web-page is the semi-official home
of Fancylads on the World Wide Web.</font>
</p>
CSS
Associated Style Sheet
9
h1{
background:url(fancy-header.png) no-repeat;
width:207px;
height:279px;
text-indent:-9999px;
}
p {
text-align:center;
font-family:papyrus;
}
CSS
CSS properties for colors
10
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
11
p { color: red; }
h2 { color: rgb(128, 0, 196); }
h4 { color: #FF8800; }
CSS
p, h1, h2 {
color: green;
}
h2 {
background-color: yellow;
} CSS
CS380
CSS comments /*…*/
13
/* 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
14
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
15
p {
font-family: Georgia;
}
h2 {
font-family: "Courier New";
} CSS
CS380
More about font-family
16
p {
font-family: Garamond, "Times New Roman", serif;
} CSS
p {
font-size: 24pt;
} CSS
CS380
font-size
18
p {
font-size: 24pt;
} CSS
CS380
font-weight, font-style
19
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
20
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
21
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
22
p {
text-decoration: underline;
} CSS
CS380
The list-style-type property
23
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
24
body {
font-size: 16px;
}
CSS
CS380
Cascading Style Sheets
25
CS380
Inheriting styles
26
CSS
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
28
<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
29
property description
background-color color to fill background
background-image image to place in background
placement of bg image within
background-position
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
30
body {
background-image: url("images/draft.jpg");
}
CSS
CS380
background-repeat
31
body {
background-image: url("images/draft.jpg");
background-repeat: repeat-x;
}
CSS
CS380
background-position
32
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