Web 03 CSS
Web 03 CSS
Web 03 CSS
Charles Severance
www.wa4e.com
https://www.wa4e.com/code/css.zip
Time Browser Web Server Database Server
D
Apache
O static MySql
Parse
M Request
files
Parse
Response
PHP php
code
JavaScrip
t
RRC/HTTP SQL
More than
Developer
Console
http://chrispederick.com/work/web-developer/
HTML has evolved a *lot* over
the years - as computers and
networks have gotten faster
1995
2007
Without CSS
With CSS
HTML
CSS
Separation of Concerns / Specialization
Developer Designer body {
font-family: arial, sans-serif;
}
<html> h1 {
<head> color: blue;
<title>Including CSS From a File</title> }
<link type="text/css" rel="stylesheet" href="rules.css"> p{
</head> border-style: solid;
<body> border-color: red;
<h1>A Header</h1> border-width: 5px;
<p> }
By putting the CSS rules into a separate file, a{
it can be included in many different web pages color: green;
with a single "link" tag, usually in the background-color: lightgray;
"head" of the document. text-decoration: none;
</p> }
CSS Syntax
• CSS Syntax is very different than HTML.
body {
font-family: arial, sans-serif;
}
Anatomy of a CSS Rule
selector - which part of the
document this rule applies to
body {
font-family: arial, sans-serif;
font-size: 100%;
}
http://www.lesliefranke.com/files/reference/csscheatsheet.html
Using CSS in HTML
Applying CSS to our HTML
• Inline - right on an HTML tag, using the style= attribute
• An embedded style sheet in the <head> of the document
• As an external style sheet in a separate file
<html>
<head>
<title>Including CSS From a File</title>
<link type="text/css" rel="stylesheet" href="rules.css">
</head>
<body>
<h1>A Header</h1>
csev $ ls -l
total 32
-rw-r--r-- 1 csev staff 44 Dec 19 06:06 rules.css
-rw-r--r-- 1 csev staff 679 Dec 19 06:07 index.htm
-rw-r--r-- 1 csev staff 883 Dec 19 05:59 include.htm
-rw-r--r-- 1 csev staff 679 Dec 19 05:59 colors.htm
csev $
span and div Tags
<p style="border: 1px green solid;">
With CSS we wanted some tags that had no pre-existing style. So the <span style="color:
green;">span</span> tag was invented as the new "inline" tag with no styling.
</p>
<div style="border: 1px blue solid;">
And the <strong>div</strong> tag is a new unstyled block tag with no padding, margin, background-
color, or anything else. So you could mark blocks with the div tag and not inherit any default style.
<div style="border: 1px orange solid;">
And the <strong>div</strong> tags can be nested as well. Adding the 1-pixel borders does take up a pixel
of space.
</div>
You can add some text in the outer div.
</div>
<p style="border: 1px green solid;">
With CSS we wanted some tags that had no pre-existing
Style. So the <span style="color: green;">span</span>
tag was invented as the new "inline" tag with no styling.
</p>
<div style="border: 1px blue solid;">
And the <strong>div</strong> tag is a new unstyled
block tag with no padding, margin, background-color,
or anything else. So you could mark blocks with
the div tag and not inherit any default style.
<div style="border: 1px orange solid;">
And the <strong>div</strong> tags can be nested as well.
Adding the 1-pixel borders does take up a pixel of space.
</div>
You can add some text in the outer div.
</div>
Images, Colors, and Fonts
Color Names
• W3C has listed 16 official color
names that will validate with an
HTML validator.
http://www.w3schools.com/html/html_colors.asp
Advanced Colors...
Three numbers,
Red, Green, and
Blue - each from
#e2edff
00 - FF
(Hexidecimal)
#ffffff = white
#000000 = black
#ff0000 = red
#00ff00 = green
#0000ff = blue
Web-safe
colors
http://www.w3schools.com/css/css_colornames.asp
Fonts
• Default fonts are ugly and they have
serifs - which make them harder to
read on a screen
• So the first thing I usually want to do
is override the fonts in my document
• And I want to do this everywhere
Fonts
Most Favorite Least Favorite
body {
font-family: "Trebuchet MS", Helvetica, Arial, sans-serif;
font-size: x-large;
}
Styling Links
font-weight: bold;
}
a:link {
color: black;
}
a:visited { link - before a visit
color: gray; visited - after it has been visited
} hover - when your mouse is over it
a:hover {
text-decoration: none;
but you have not clicked
color: white; active - you have clicked it and you
background-color: navy; have not yet seen the new page
}
a:active {
color: aqua;
background-color: navy;
}
Many
More
Samples
wa4e.com
CSS Summary
• CSS layout is its own art and science.
• CSS basics are well established and well supported in all modern
browsers.