Professional Documents
Culture Documents
</BODY>
</HTML>
The result
The result while hovering
Discussion
A.nodec {text-decoration: none}
– applies the text-decoration property to all A
elements whose CLASS attribute is set to
nodec
– default is to underline but here it is set to none
A:hover {text-decoration: underline;
color: red
background-color: #CCFFCC}
Pseudo-class
The code specifies a style for hover
which is a pseudo-class
Pseudo-classes give the author access
to content not specifically declared in the
document
The hover pseudo-class is dynamically
activated when the user moves the
mouse cursor over an A element
LI EM is different from LI, EM
LI EM { color: red;
font-weight: bold }
– declares a style for all EM elements that are
children of LI elements
LI, EM would declare the style for both
UL UL {text-decoration: underline;
margin-left: 15px }
– specifies that all nested lists will be underlined
and have a left-hand margin of 15 pixels
Length measurements
Px - pixel - relative - screen resolution
em - the size of the font - relative
ex - x height of the font
in - inches - absolute
pt - 1 pt = 1/72 in
pc - 1 pc = 12pt
Linking External Style Sheets
External linking of style sheets can give the whole
site a uniform look
Only need to modify a single file to make changes to
the whole site
The external style sheet is referenced by using the
<LINK> tag in <HEAD>
– <LINK REL = "stylesheet" TYPE = "text/css" HREF =
"styles.css">
LINK a specifies a relationship between the current
document and another using the REL attribute
Example: External SS
<HTML>
<!-- imported.html -->
<!-- Linking external style sheets -->
<HEAD>
<TITLE>Importing style sheets</TITLE>
<LINK REL = "stylesheet" TYPE = "text/css" HREF = "styles.css
</HEAD>
<BODY>
<H1>Shopping list for <EM>Monday</EM>:</H1>
<UL>
<LI>Milk</LI>
<LI>Bread
<UL>
<LI>White bread</LI>
<LI>Rye bread</LI>
<LI>Whole wheat bread</LI>
</UL></LI>
<LI>Rice</LI>
<LI>Potatoes</LI>
<LI>Pizza <EM>with mushrooms</EM></LI>
</UL>
<A HREF = "http://food.com">Go to the Grocery store</A>
</BODY> </HTML>
Notes
Declare the linked document to be a
stylesheet
TYPE attribute is used to specify the
MIME type as text/css
URL for the style sheet is provided by
the HREF attribute
Note
Other relationships that can be specified
between documents are next and
previous
Allow a whole series of documents to be
linked
In IE Print all linked documents uses
this info
Positioning Elements
Usually positioning was up to the
browser in HTML
CSS has a position property and a
capability called absolute positioning
Absolute positioning
<BODY>
</BODY>
Positioning
Positioning
Specifying an element’s position removes it
from the normal flow of elements on the page
Positions the element according to distance
from top, left, right or bottom margins of its
parent element
I.gif is 0 pixels from top and left margins of the
BODY element
z-index attribute allows layering of overlapping
elements (1 back - 2 front)
Absolute positioning
Where does the H1 element go.
Layer 3 in front of both
Relative positioning
Setting the position property to relative
will first lay out the element on the page,
then offset the element by the specified
top, bottom, left or right values
Relative positioning keeps elements in
the general flow of elements on the
page
Relative Positioning
<HEAD>
<STYLE TYPE = "text/css">
P { font-size: 2em;
font-family: Verdana, Arial, sans-serif}
SPAN { color: red;
font-size: .6em;
height: 1em }
.super { position: relative;
top: -1ex }
.sub { position: relative;
bottom: -1ex }
.shiftl { position: relative;
left: -1ex }
.shiftr { position: relative;
right: -1ex }
</STYLE></HEAD>
Relative positioning
<BODY>
<P>
Text text text text <SPAN CLASS = "super">superscript</SPAN>
text text text text <SPAN CLASS = "sub">subscript</SPAN>
text Text text <SPAN CLASS = "shiftl">left-shifted</SPAN>
text text text <SPAN CLASS = "shiftr">right-shifted</SPAN>
Text text text text text
</P>
</BODY>
</HTML>
Display
Backgrounds
CSS allows more control over background
than HTML attributes
<STYLE TYPE = "text/css">
BODY { background-image: url(watermark.gif);
background-position: bottom right;
background-repeat: no-repeat;
background-attachment: fixed }
P { font-size: 2em;
color: #AA5588;
text-indent: 1em;
font-family: Arial, sans-serif }
.dark { font-weight: bold }
</STYLE>
Backgrounds
background-image property specifies the
URL of the image to use
– can also specify background-color in case
the image is not found
background-position property positions
image on page
background repeat property controls tiling
no repeat, repeat, x-repeat or y-repeat
Backgrounds
Background-attachment: fixed fixes the image
in the position specified by background-
position
– scrolling the browser window will not move the
image - default scroll moves the image
text-indent: 1em indents the first line of text
.dark {font-weight: bold}
– font weight specifies the boldness - bold, normal,
bolder, lighter
SPAN, DIV
Font-style - none, italic or oblique
SPAN is a generic grouping element which
does not apply any formatting to its contents
– Its use is to apply styles or ID attributes to a
block of text. It is displayed inline
DIV element also applies no inherent styles
but is displayed on its own line.
– A block-level element
DIV
<HEAD>
<TITLE>Box Dimensions</TITLE>
<STYLE TYPE = "text/css">
DIV { background-color: #FFCCFF;
margin-bottom: .5em }
</STYLE></HEAD>
<BODY>
<DIV STYLE = "width: 20%">Here is some
text that goes in a box which is
set to stretch across twenty precent
of the width of the screen.</DIV>
.5em padding
Text flow and the Box Model
Note that the DIV elements are 50% width
STYLE = “text-align: center” allows the
text inside an element to be aligned left,
center, right or justify
STYLE=“float: right; margin: .5em”>
– floats the DIV element to the right side of
screen - margin specifies the distance
between the element and any text outside.
Text flow and the Box Model
Can set margins for individual sides by using
margin-top, margin-right etc
Padding is the distance between the content
inside the element and the edge of the element
padding-top, padding-right etc.
The flow of text around a floated element can be
interrupted
– <SPAN STYLE=“clear: right”>
Box model applies to DIV, P
Borders
<HEAD>
<STYLE TYPE = "text/css">
BODY { background-color: #CCFFCC }
DIV { text-align: center;
margin-bottom: 1em;
padding: .5em }
.thick { border-width: thick }
.medium { border-width: medium }
.thin { border-width: thin }
.groove { border-style: groove }
.inset { border-style: inset }
.outset { border-style: outset }
.red { border-color: red }
.blue { border-color: blue }
</STYLE></HEAD>
Borders
<BODY>
</BODY>
</HTML>
Borders
User Style Sheets
Users have the option to define their own
user style sheets to format pages based on
their preferences - visually impaired
Possible conflicts between user styles and
author styles
Most conflicts are resolved by using
relative measurements such as em or ex
User Style Sheets
Adding a user style sheet in IE is done
by Tools|Internet Options|Accessibility|
Format documents using my style sheet
Resources
http://www.w3.org/T/REC-CSS2/
http://style.webreview.com