Unit 1.2.2 CSS
Unit 1.2.2 CSS
@import "/CSS/graphical.css"/**/;
p.text strong, .verbose, .verbose p, .verbose h2{text-indent:-
876em;position:absolute}
p.text strong a{text-decoration:none}
p.text em{font-weight:bold;font-style:normal}
div.alert{background:#eee;border:1px solid
red;padding:.5em;margin:0 25%}
In the modern era of web design a img{border:none}
we represent content and meaning .hot br, .quick br, dl.feature2 img{display:none}
div#main label, legend{font-weight:bold}
in HTML and formatting and
layout in CSS.
Source: http://www.umich.edu
HTML has evolved a *lot* over the
years - as computers and networks
have gotten faster.
1995
2007
Source: www.yahoo.com
CSS Allows Separation of effort / specialization
Developer Designer
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 @import "/CSS/graphical.css"/**/;
Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- p.text strong, .verbose, .verbose p, .verbose h2{text-indent:-
strict.dtd"> 876em;position:absolute}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> p.text strong a{text-decoration:none}
<head> p.text em{font-weight:bold;font-style:normal}
<title>University of Michigan</title> div.alert{background:#eee;border:1px solid
....
...
Everyone needs to know some HTML and some CSS and some programming - but to be truly
skilled at a professional level requires deep understanding and specialization.
Tranforming the look and feel of a page using a CSS style sheet.
body {
font-family: arial, san-serif;
}
a, a:link
{
color: #0000cc;
}
...
Applying Basic Styles
The Browser has “default styling” for all tags.
<h1><a href="index.htm">
AppEngineLearn</a></h1>
<ul>
<li><a href="sites.htm">Sites</a></li>
<li><a href="topics.htm" >Topics</a></li>
</ul>
<h2>Google App Engine: About</h2>
<p>
Welcome to the site dedicated to
learning the Google Application Engine.
We hope you find
www.appenginelearn.com useful.
</p>
We will apply CSS to the tags in the document.
h1, h2, h3 {
color: yellow;
background-color: black;
}
</style>
</head>
<body>
<h1><a href="index.htm">
AppEngineLearn</a></h1>
<ul>
<li><a href="sites.htm">Sites</a></li>
<li><a href="topics.htm" >Topics</a></li> </ul>
<html xmlns="http://www.w3.org/1999/xhtml"> External Style
<head>
<title>Learning the Google App Engine</title>
Sheets
<link type="text/css" rel="stylesheet" href="glike.css">
</head>
<body>
<h1><a href="index.htm">
AppEngineLearn</a></h1>
<ul> glike.css:
<li><a href="sites.htm">Sites</a></li>
body {
<li><a href="topics.htm" >Topics</a></li> font-family: arial, sans-serif;
</ul> }
Fonts
Source: http://www.w3schools.com/html/html_colors.asp
Colors by the number...
Three Numbers, Red, #e2edff
Green , and Blue -
each from 00 - FF #edf = #eeddff
(Hexidecimal)
#ffffff = white
#000000 = black
#ff0000 = red
#00ff00 = green
#0000ff = blue
Web-safe
colors
Source: http://www.w3schools.com/css/css_colornames.asp
Default Styling for Links
Post-Click:
Downright Ugly!
Source: www.yahoo.com
a{
font-weight: bold;
}
a:link {
Styling Links
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 { but you have not clicked
text-decoration: none;
color: white;
active - you have clicked it and you
background-color: navy; have not yet seen the new page
}
a:active {
color: aqua;
Browser default styling for links is
background-color: navy; downright ugly!
}
CSS Tags and Attributes
• As CSS was introduced they introduced two new tags that are pretty much
there to serve as handles for styling
• id= - Marks a unique block within the document for styling (use only once)
• class= - Marks a non-unique tag within the document for styling (multi-use)
div as Container
<div> The id attribute on the tag allows us to
<p>This is a paragraph inside a div.</p> uniquely mark a div in a document. The id
<p>So is this.</p> tag is also useful for screen readers.
</div>
<div id="header">
<ul>
<li><a href="sites.htm">Sites</a></li> <li><a
href="topics.htm" >Topics</a></li>
</ul>
</div>
“div” stands for “division” as it allows us to divide our page into parts or sections
and then do something different with each “section”.
Styling a block with “id”
Everything within block Paragraphs within block
#footer { #footer p {
font-style: italic; font-style: italic;
font-family: Times, serif;
or font-family: Times, serif;
} }
<div id="footer">
<p>Please send any comments to csev@umich.edu</p>
</div>
id= identifies a *particular* block - only one in a document
Nested divs
<div id="outer">
<div id="nested1">
<p>A paragraph inside the first nested div.</p>
</div>
<div id="nested2">
<p>A paragraph inside the second nested div.</p>
</div>
</div> <!-- End of the outer div -->
Sometimes you want to style something smaller than a whole block - then use span. Do not use span if you are
applying something to a whole block - just put your styling on the enclosing block tag.
<body>
<div id="header">
<h1><a href="index.htm“class="selected">SI502</a></h1>
<ul class="toolbar">
<li><a href="books.htm">Books</a></li> When building HTML, we
<li><a href="topics.htm" >Topics</a></li>
</ul>
use id and class to add little
“handles” in the HTML to
</div> make it so we can “style”
<div id="bodycontent"> areas of the document.
<h1>Networked Computing: About</h1>
<p>
This course is a survey course covering a broad
range of technology topics at a high level.
The course is aimed at students with no prior
Pick div id’s to
technical skills other than the general use of indicate meaning.
a computer. Really!
</p>
</div>
</body>
A Running Example...
Transform from ugly to fancy with CSS
First: Just work with the tags and fix fonts / colors
<head>
<title>Learning the Google App Engine</title>
<link type="text/css" rel="stylesheet" href="glike.css">
</head>
body {
font-family: arial, sans-serif;
}
a{
color: blue;
}
h1 a {
text-decoration: none;
color: black;
}
Block Layout
Source: www.dr-chuck.com
Two kinds of elements
• Inline - affects how text looks
• strong, span #navigation li {
• Block - Containers that can be laid out display: inline;
}
• Paragraphs, etc
• CSS can change a tag from inline to
block
Inline Elements
• Flowed with other text
• span, em, strong, cite, a
• Inline tags can be nested as long as they match
• <span class=”important”><cite>Stuff</cite></span>
• Block can contain inline - but inline cannot contain block
Block Level Elements
• Starts on its own line - ends
<div id=”content”>
justification and starts a new block
<p>One </p>
• Can be a container for other <p>Two</p>
</div>
elements
• padding properties define the space between the element border and the
element content
<p class=”trapped”>
I am trapped in a glass case of emotion
which is 100px high and 200px wide. The Box Model
</p>
.trapped {
height: 50px;
width: 50px;
}
.trapped2 {
height: 50px;
width: 50px;
border: 5px solid yellow;
padding: 10px;
}
<p class="trapped">
One</p>
<p class="trapped2"> Border, padding, and margin are additive.
Two</p>
#header { #header li {
background-color: #dde;
font-size: 14px;
border-top: 3px solid #36c;
display: inline;
height: 100%;
padding: .5em;
overflow:hidden;
padding: 7px; }
margin-top: 5px; #header ul {
} list-style: none;
#header h1 { text-align: right;
font-size: 20px; float:right;
float: left; vertical-align: middle;
vertical-align: middle; margin: 0;
margin: 0; padding: 0;
padding: 0 0 0 .3em; }
}
top, right, bottom, left
<div id="header">
<h1><a href="index.htm">AppEngineLearn</a></h1>
<ul>
<li><a href="sites.htm" class="selected">Sites</a></li>
<li><a href="topics.htm" >Topics</a></li>
</ul>
</div>
#header li a.selected {
color: black;
text-decoration: none;
}
<div id="header">
<h1><a href="index.htm">AppEngineLearn</a></h1>
<ul>
<li><a href="sites.htm">Sites</a></li>
<li><a href="topics.htm" class="selected">Topics</a></li>
</ul>
</div>
Tranforming the look and feel of a page using a CSS style sheet.
body {
font-family: arial, san-serif;
}
a, a:link
{
color: #0000cc;
}
...
CSS Validation
• You can validate your CSS to make sure it has no syntax errors
• http://jigsaw.w3.org/css-validator
• CSS Basics are well established and well supported in all modern browsers
• The box model is pretty straightforward - and allows nice design within the
standards with reasonable effort levels.