Except where otherwise noted, the contents of this document are Copyright 2012 Marty Stepp, Jessica Miller, and Victoria Kirst. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.
<p> <font face="Arial">Welcome to Greasy Joe's.</font> You will <b>never</b>, <i>ever</i>, <u>EVER</u> beat <font size="+4" color="red">OUR</font> prices! </p>
b, i, u, and font are discouraged in strict HTML
<link>
<head> ... <link href="filename" type="text/css" rel="stylesheet" /> ... </head>
<link href="style.css" type="text/css" rel="stylesheet" />
.css file (preferred)
selector {
property: value;
property: value;
...
property: value;
}
p {
font-family: sans-serif;
color: red;
}
* selects all elements
p {
color: red;
background-color: yellow;
}
This paragraph uses the style above.
| property | description |
|---|---|
color
|
color of the element's text |
background-color
|
color that will appear behind the element |
p { color: red; }
h2 { color: rgb(128, 0, 196); }
h4 { color: #FF8800; }
This paragraph uses the first style above.
aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white (white), yellow| 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 |
| Complete list of font properties | |
font-family
p {
font-family: Georgia;
}
h2 {
font-family: "Courier New";
}
This paragraph uses the first style above.
font-family
p {
font-family: Garamond, "Times New Roman", serif;
}
This paragraph uses the above style.
font-family value ensures that every computer will use a valid fontfont-size
p {
font-size: 14pt;
}
This paragraph uses the style above.
px) vs. point (pt) vs. m-size (em)16px, 16pt, 1.16emxx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger90%, 120%pt specifies number of point, where a point is 1/72 of an inch onscreenpx specifies a number of pixels on the screenem specifies number of m-widths, where 1 em is equal to the font's current sizefont-weight,
font-style
p {
font-weight: bold;
font-style: italic;
}
This paragraph uses the style above.
normal to turn them off (e.g. headings)
selector {
property: value;
property: value;
...
property: value;
}
p {
font-family: sans-serif;
color: red;
}
p, h1, h2 {
color: green;
}
h2 {
background-color: yellow;
}
This paragraph uses the above style.
h2 above)/* ... */
/* This is a comment.
It can span many lines in the CSS file. */
p {
color: red;
background-color: aqua;
}
// single-line comment style is NOT supported in CSS<!-- ... --> HTML comment style is also NOT supported in CSS<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>
| property | description |
|---|---|
text-align
|
alignment of text within its element |
text-decoration
|
decorations such as underlining |
line-height, word-spacing, letter-spacing
|
gaps between the various portions of the text |
text-indent
|
indents the first letter of each paragraph |
| Complete list of text properties | |
text-align
blockquote { text-align: justify; }
h2 { text-align: center; }
[TO LUKE SKYWALKER] The alliance... will die. As will your friends. Good, I can feel your anger. I am unarmed. Take your weapon. Strike me down with all of your hatred and your journey towards the dark side will be complete.
left, right, center, or justify (which widens all full lines of the element so that they occupy its entire width) text-decoration
p {
text-decoration: underline;
}
This paragraph uses the style above.
overline, line-through, blink, or nonetext-decoration: overline underline;
| property | description |
|---|---|
background-color
|
color to fill background |
background-image
|
image to place in background |
background-position
|
placement of bg image within element |
background-repeat
|
whether/how bg image should be repeated |
background-attachment
|
whether bg image scrolls with page |
background
|
shorthand to set all background properties |
background-image
body {
background-image: url("images/draft.jpg");
}
This is the first paragraph
This is the second paragraph...
It occupies 2 lines
background-repeat
body {
background-image: url("images/draft.jpg");
background-repeat: repeat-x;
}
This is the first paragraph
This is the second paragraph...
It occupies 2 lines
repeat (default), repeat-x, repeat-y, or no-repeatbackground-position
body {
background-image: url("images/draft.jpg");
background-repeat: no-repeat;
background-position: 370px 20px;
}
This is the first paragraph
This is the second paragraph...
It occupies 2 lines
top, left, right, bottom, center, a percentage, or a length value in px, pt, etc.list-style-type property
ol { list-style-type: lower-roman; }
none : No markerdisc (default), circle, squaredecimal : 1, 2, 3, etc.decimal-leading-zero : 01, 02, 03, etc.lower-roman : i, ii, iii, iv, v, etc.upper-roman : I, II, III, IV, V, etc.lower-alpha : a, b, c, d, e, etc.upper-alpha : A, B, C, D, E, etc.lower-greek : alpha, beta, gamma, etc.hebrew, armenian, georgian, cjk-ideographic, hiragana, katakana, hiragana-iroha, katakana-iroha
table { border: 2px solid black; caption-side: bottom; }
tr { font-style: italic; }
td { background-color: yellow; text-align: center; width: 30%; }
| Column 1 | Column 2 |
|---|---|
| 1,1 | 1,2 okay |
| 2,1 real wide | 2,2 |
border-collapse property
table, td, th { border: 2px solid black; }
table { border-collapse: collapse; }
| Column 1 | Column 2 |
|---|---|
| 1,1 | 1,2 |
| 2,1 | 2,2 |
| Column 1 | Column 2 |
|---|---|
| 1,1 | 1,2 |
| 2,1 | 2,2 |
border-collapse property merges these borders into onerowspan and colspan attributes<table> <tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr> <tr><td colspan="2">1,1-1,2</td> <td rowspan="3">1,3-3,3</td></tr> <tr><td>2,1</td><td>2,2</td></tr> <tr><td>3,1</td><td>3,2</td></tr> </table>
colspan makes a cell occupy multiple columns; rowspan multiple rowstext-align and vertical-align control where the text appears within a cell<col>,
<colgroup>
<table> <col class="urgent" /> <colgroup class="highlight" span="2"></colgroup> <tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr> <tr><td>1,1</td><td>1,2</td><td>1,3</td></tr> <tr><td>2,1</td><td>2,2</td><td>2,3</td></tr> </table>
col tag can be used to define styles that apply to an entire column (self-closing)colgroup tag applies a style to a group of columns (NOT self-closing)table has semantics; it should be used only to represent an actual table of datadivs, widths/margins, floats, etc. to perform layoutnth-child, inline-block, :not, +
body {
font-size: 16px;
}
body element
body { color: green; }
p, h1, h2 { color: blue; font-style: italic; }
h2 { color: red; background-color: yellow; }
This paragraph uses the first style above.
<style> (BAD!)
<head>
<style type="text/css">
p { font-family: sans-serif; color: red; }
h2 { background-color: yellow; }
</style>
</head>
head of an HTML pagestyle attribute (BAD!)
<p style="font-family: sans-serif; color: red;"> This is a paragraph</p>
.css files<link> tag)<style> tag in the page header)style attribute of an HTML element)
body { font-family: sans-serif; background-color: yellow; }
p { color: red; background-color: aqua; }
a { text-decoration: overline underline; }
h2 { font-weight: bold; text-align: center; }
A styled paragraph. Previous slides are available on the web site.
a:link { color: #FF0000; } /* unvisited link */
a:visited { color: #00FF00; } /* visited link */
a:hover { color: #FF00FF; } /* mouse over link */
| class | description |
|---|---|
:active
|
an activated or selected element |
:focus
|
an element that has the keyboard focus |
:hover
|
an element that has the mouse over it |
:link
|
a link that has not been visited |
:visited
|
a link that has already been visited |
:first-letter
|
the first letter of text inside an element |
:first-line
|
the first line of text inside an element |
:first-child
|
an element that is the first one to appear inside another |
:nth-child(N)
|
applies to every Nth child of a given parent |