03 Css
03 Css
Welcome to Greasy Joe's. You will never, ever, EVER beat OUR prices!
the above tags such as b, i, u, and font are legal in older HTML but are deprecated in strict XHTML
you should not use the above tags on your homework assignments!
why are we discouraged from expressing stylistic information this way?
p {
font-family: sans-serif;
color: red;
}
Specifying colors
p { color: red; }
h2 { color: rgb(128, 0, 196); }
h4 { color: #FF8800; }
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)
font-family
p { font-family: "Georgia"; }
h2 { font-family: "Arial Narrow"; }
if the first font is not found on the user's computer, the next is tried
generally should specify similar fonts
placing a generic font name at the end of your font-family value ensures that every computer will use
a valid font
font-size
p { font-size: 14pt; }
vague font sizes: xx-small, x-small, small, medium, large, x-large, xx-large
relative font sizes: smaller, larger
percentage font sizes, e.g.: 90%, 120%
units: pixels (px) vs. point (pt) vs. m-size (em)
16px, 16pt, 1.16em
font-weight, font-style
p {
font-weight: bold;
font-style: italic;
}
either of the above can be set to normal to turn them off (e.g. headings)
Body styles
body { font-size: 16px; }
to apply a style to the entire body of your page, write a selector for the body element
saves you from manually applying a style to each element
KITTENS! Edit this HTML and add the following styles to it:
entire page should have a pink background and use 16 point font
main heading should use Comic Sans MS font
lists should appear in a Lucida Console font
list numbers should have yellow background; list items should have
green background
link text should be purple
quote text should be italicized
Why I love them:
1. They are little.
2. They make adorable sounds:
"Meow!"
"Purr!"
3. JUST LOOK AT THEM!
Now if I want to strongly emphasize something or just emphasize it, it doesn't necessarily have to be bold or
italic.
strong and em describe attributes of the content (it is something important in the document that you
want to emphasize)
b and i describe formatting and presentation ("I want this to be bold.")
text-align
blockquote { text-align: justify; }
h2 { text-align: center; }
text-align can be 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; }
CSS (like HTML) is usually not commented as rigorously as programming languages such as Java
the // single-line comment style is NOT supported in CSS
Grouping styles
p,h1,h2 { color: blue; }
h2 { background-color: yellow; }
Document tree
<html><head><title>My home page</title></head>
<body><h1>My home page</h1>
<p>Let me tell you about my favorite composers:</p>
<ul><li>Elvis Costello</li>
<li>Johannes Brahms</li>
<li>Georges Brassens</li>
</ul></body></html>
This is a heading.
A styled paragraph. Previous slides are available on the web site.
a bullet list
when two styles set conflicting values for the same property, the latter style takes precedence
jigsaw.w3.org/css-validator/
checks your CSS to make sure it meets the official CSS specifications
more picky than the web browser, which may render malformed CSS correctly
KITTENS!
Edit the previously-styled Kitten HTML and add the following styles:
selectively applies a CSS rule to only the paragraphs that are part of the class named special (next slide)
gives a style to some occurrences of an element but not others
("I don't want ALL paragraphs to be yellow, just these three...")
selectively applies a CSS rule to any element that is part of the class named standout
Satisfaction guaranteed.
CSS ID selectors
p#missionstatement {
font-style: italic;
font-family: "Garamond", "Century Gothic", serif;
}
selectively applies a CSS rule to only the paragraphs that has the particular ID named
missionstatement (next slide)
differs from class selector in that an ID can only be used once in the HTML document (won't validate
otherwise)
element (p above) can be omitted if desired; rule will apply to any element with ID
missionstatement
Our mission is to provide the most spectacular spatulas and splurge on our specials until our customers "esplode" with splendor!
has no onscreen appearance, but you can apply a style or ID to it, which will be inherited by all elements
inside the div
has no onscreen appearance, but you can apply a style or ID to it, which will be applied to the text inside
the span
This is a paragraph
background-image
body {
background-image: url("draft.jpg");
}
background-repeat
body {
background-image: url("draft.jpg");
background-repeat: repeat-x;
}
background-position
body {
background-image: url("draft.jpg");
background-repeat: no-repeat;
background-position: 370px 20px;
}
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
Context selectors
selector1 selector2 {
properties
}
applies the given properties to selector2 only if it is inside a selector1 on the page
selector1 > selector2 {
properties
}
applies the given properties to selector2 only if it is directly inside a selector1 on the page (selector1 tag is
immediately inside selector2 with no tags in between)
<div id="ad">
<p>Shop at <strong>Hardwick's Hardware</strong>...</p>
<ul>
<li class="important">The <strong>best</strong>
prices in town!</li>
<li>Act <strong>while supplies last!</strong></li>
</ul>
</div>
Pseudo-classes
a:link {color: #FF0000} /* unvisited link */
a:visited {color: #00FF00} /* visited link */
a:hover {color: #FF00FF} /* mouse over link */
a:active {color: #0000FF} /* selected link */
Pseudo-class example
a:link {color: red}
a:visited {color: green}
a:hover {color: purple; background-color: yellow;}
a:active {color: blue}
<a href="http://www.google.com">Goooooogle</a>
Goooooogle
How would we make unvisited links blue, only they are in a paragraph inside of the div with id header
or id footer?
answer:
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.
ix. lower-greek : alpha, beta, gamma, etc.
x. others: hebrew, armenian, georgian, cjk-ideographic, hiragana, katakana,
hiragana-iroha, katakana-iroha