Css
Css
semantics (the look and formatting) of a document written in a markup language. Its most
common application is to style web pages written in HTML and XHTML.
CSS is designed primarily to enable the separation of document content (written in HTML or
a similar markup language) from document presentation, including elements such as the
layout, colors, and fonts. This separation can improve content accessibility, provide more
flexibility and control in the specification of presentation characteristics, enable multiple
pages to share formatting, and reduce complexity and repetition in the structural content
(such as by allowing for tableless web design). CSS can also allow the same markup page to
be presented in different styles for different rendering methods, such as on-screen, in print,
by voice (when read out by a speech-based browser or screen reader) and on Braille-based,
tactile devices. It can also be used to allow the web page to display differently depending on
the screen size or device on which it is being viewed. While the author of a document
typically links that document to a CSS style sheet, readers can use a different style sheet,
perhaps one on their own computer, to override the one the author has specified.
CSS specifies a priority scheme to determine which style rules apply if more than one rule
matches against a particular element. In this so-called cascade, priorities or weights are
calculated and assigned to rules, so that the results are predictable.
A style sheet consists of a list of rules. Each rule or rule-set consists of one or more
selectors, and a declaration block. A declaration-block consists of a list of declarations in
braces. Each declaration itself consists of a property, a colon (:), and a value. If there are
multiple declarations in a block, a semi-colon (;) must be inserted to separate each
declaration. In CSS, selectors are used to declare which part of the markup a style applies to,
a kind of match expression. Selectors may apply to all elements of a specific type, to
elements specified by attribute, or to elements depending on how they are placed relative
to, or nested within, others in the document tree.
Selector
{
Font-family : arial;
Properties
Font-size : medium;
Values
Color : blue;
}
CSS information can be provided from various sources. CSS style information can be in a
separate document or it can be embedded into an HTML document. Multiple style sheets
can be imported.
Inline styles, inside the HTML document, style information on a single element,
specified using the style attribute
Embedded or internal style, blocks of CSS information inside the <head> element of
HTML itself
External style sheets, i.e., a separate CSS file referenced from the document
Color:blue;
Text-align:justify;
}
H1
{
Font-family:arial black;
Background-color:blue;
Color:white;
}
Create another new document in notepad and create a html file with the following html
markup. To link an external css file, use <link> element of html within the <head> element.
<!doctype html>
<html>
<head>
<link rel=stylesheet type=text/css href=MyStyle.css/>
</head>
<body>
<h1> Heading </h1>
<p> This is a paragraph formatted with internal css style. </p>
</body>
</html>
Selector syntax
A simple selector is either a type selector or universal selector followed immediately by zero
or more attribute selectors, ID selectors, or pseudo-classes, in any order. The simple
selector matches if all of its components match.
A selector is a chain of one or more simple selectors separated by combinators. Combinators
are: white space, ">", and "+". White space may appear between a combinator and the
simple selectors around it.
The elements of the document tree that match a selector are called subjects of the selector.
A selector consisting of a single simple selector matches any element satisfying its
requirements. Prepending a simple selector and combinator to a chain imposes additional
matching constraints, so the subjects of a selector are always a subset of the elements
matching the last simple selector.
One pseudo-element may be appended to the last simple selector in a chain, in which case
the style information applies to a subpart of each subject.
Grouping
When several selectors share the same declarations, they may be grouped into a commaseparated list.
In this example, we condense three rules with identical declarations into one. Thus,
h1 { font-family: sans-serif }
h2 { font-family: sans-serif }
h3 { font-family: sans-serif }
is equivalent to:
h1, h2, h3 { font-family: sans-serif }
Universal selector
The universal selector, written "*", matches the name of any element type. It matches any
single element in the document tree. If the universal selector is not the only component of a
simple selector, the "*" may be omitted. For example:
*[lang=fr] and [lang=fr] are equivalent.
*.warning and .warning are equivalent.
*#myid and #myid are equivalent.
Type selectors
A type selector matches the name of a document language element type. A type selector
matches every instance of the element type in the document tree.
The following rule matches all H1 elements in the document tree:
h1 { font-family: sans-serif }
Descendant selectors
At times, authors may want selectors to match an element that is the descendant of
another element in the document tree (e.g., "Match those EM elements that are contained
4
Child selectors
A child selector matches when an element is the child of some element. A child selector is
made up of two or more selectors separated by ">".
The following rule sets the style of all P elements that are children of BODY:
body > P { line-height: 1.3 }
The following example combines descendant selectors and child selectors:
div ol>li p
It matches a P element that is a descendant of an LI; the LI element must be the child of an
OL element; the OL element must be a descendant of a DIV. Notice that the optional white
space around the ">" combinator has been left out.
Attribute selectors
CSS 2.1 allows authors to specify rules that match elements which have certain attributes
defined in the source document.
The following selectors illustrate the differences between "=" and "~=". The first selector will
match, for example, the value "copyright copyleft copyeditor" for the "rel" attribute. The
second selector will only match when the "href" attribute has the value
"http://www.nareshit.com/".
a[rel~="copyright"]
a[href="http://www.nareshit.com/"]
The following rule hides all elements for which the value of the "lang" attribute is "fr" (i.e.,
the language is French).
*[lang=fr] { display : none }
The following rule will match for values of the "lang" attribute that begin with "en",
including "en", "en-US", and "en-cockney":
*[lang|="en"] { color : red }
Similarly, the following aural style sheet rules allow a script to be read aloud in different
voices for each role:
DIALOGUE[character=romeo] { voice-family: "Laurence Olivier", charles, male }
DIALOGUE[character=juliet] { voice-family: "Vivien Leigh", victoria, female }
Class selectors
Working with HTML, authors may use the period (.) notation as an alternative to the ~=
notation when representing the class attribute. Thus, for HTML, div.value and
div[class~=value] have the same meaning. The attribute value must immediately follow the
"period" (.).
For example, we can assign style information to all elements with class~="pastoral" as
follows:
*.pastoral { color: green } /* all elements with class~=pastoral */
or just
.pastoral { color: green } /* all elements with class~=pastoral */
The following assigns style only to H1 elements with class~="pastoral":
H1.pastoral { color: green } /* H1 elements with class~=pastoral */
Given these rules, the first H1 instance below would not have green text, while the second
would:
<H1>Not green</H1>
<H1 class="pastoral">Very green</H1>
To match a subset of "class" values, each value must be preceded by a ".".
For example, the following rule matches any P element whose "class" attribute has been
assigned a list of space-separated values that includes "pastoral" and "marine":
p.marine.pastoral { color: green }
This rule matches when class="pastoral blue aqua marine" but does not match for
class="pastoral blue".
ID selectors
Document languages may contain attributes that are declared to be of type ID. What makes
attributes of type ID special is that no two such attributes can have the same value;
whatever the document language, an ID attribute can be used to uniquely identify its
element. In HTML all ID attributes are named "id"; XML applications may name ID attributes
differently, but the same restriction applies.
The ID attribute of a document language allows authors to assign an identifier to one
element instance in the document tree. CSS ID selectors match an element instance based
on its identifier. A CSS ID selector contains a "#" immediately followed by the ID value,
which must be an identifier.
The following ID selector matches the H1 element whose ID attribute has the value
"chapter1":
h1#chapter1 { text-align: center }
In the following example, the style rule matches the element that has the ID value "z98y".
The rule will thus match for the P element:
<head>
<title>match p</title>
<style type="text/css">
*#z98y { letter-spacing: 0.3em }
</style>
</head>
<body>
<p id=z98y>wide text</p>
</body>
In the next example, however, the style rule will only match an H1 element that has an ID
value of "z98y". The rule will not match the P element in this example:
<head>
<title>match h1 only</title>
<style type="text/css">
h1#z98y { letter-spacing: 0.5em }
</style>
</head>
<body>
<p id=z98y>wide text</p>
</body>
ID selectors have a higher specificity than attribute selectors. For example, in HTML, the
selector #p123 is more specific than [id=p123] in terms of the cascade.
If an element has multiple ID attributes, all of them must be treated as IDs for that element
for the purposes of the ID selector.
Pseudo-elements create abstractions about the document tree beyond those specified by
the document language. For instance, document languages do not offer mechanisms to
access the first letter or first line of an element's content. CSS pseudo-elements allow style
sheet designers to refer to this otherwise inaccessible information. Pseudo-elements may
also provide style sheet designers a way to assign style to content that does not exist in the
source document (e.g., the :before and :after pseudo-elements give access to generated
content).
Pseudo-classes classify elements on characteristics other than their name, attributes or
content; in principle characteristics that cannot be deduced from the document tree.
Pseudo-classes may be dynamic, in the sense that an element may acquire or lose a pseudoclass while a user interacts with the document. The exceptions are ':first-child', which can be
deduced from the document tree, and ':lang()', which can be deduced from the document
tree in some cases.
Neither pseudo-elements nor pseudo-classes appear in the document source or document
tree.
Pseudo-classes are allowed anywhere in selectors while pseudo-elements may only be
appended after the last simple selector of the selector.
Pseudo-element and pseudo-class names are case-insensitive.
Some pseudo-classes are mutually exclusive, while others can be applied simultaneously to
the same element. In case of conflicting rules, the normal cascading order determines the
outcome.
Pseudo-classes
:first-child pseudo-class
The :first-child pseudo-class matches an element that is the first child element of some
other element.
In the following example, the selector matches any P element that is the first child of a DIV
element. The rule suppresses indentation for the first paragraph of a DIV:
div > p:first-child { text-indent: 0 }
This selector would match the P inside the DIV of the following fragment:
<p> the last p before the note.
<div class="note">
11
/* Same */
12
*/
13
the language of the element around the quote, not the quote itself: like this piece of French
l'improviste in the middle of an English text uses the English quotation marks.
Pseudo-elements
Pseudo-elements behave just like real elements in CSS with the exceptions described below
and elsewhere.
15
might be "rewritten" by user agents to include the fictional tag sequence for :first-line. This
fictional tag sequence helps to show how properties are inherited.
<P><P:first-line> This is a somewhat long HTML
paragraph that </P:first-line> will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
If a pseudo-element breaks up a real element, the desired effect can often be described by a
fictional tag sequence that closes and then re-opens the element. Thus, if we mark up the
previous paragraph with a SPAN element:
<P><SPAN class="test"> This is a somewhat long HTML
paragraph that will be broken into several
lines.</SPAN> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
the user agent could simulate start and end tags for SPAN when inserting the fictional tag
sequence for :first-line.
<P><P:first-line><SPAN class="test"> This is a
somewhat long HTML
paragraph that will </SPAN></P:first-line><SPAN class="test"> be
broken into several
lines.</SPAN> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>
16
The following CSS 2.1 will make a drop cap initial letter span about two lines:
<!doctype html public "-//w3c//dtd html 4.01//en">
<html>
<head>
<title>drop cap initial letter</title>
<style type="text/css">
p
{ text-transform: uppercase }
</style>
</head>
<body>
<p><span>the first</span> few words of an article
in the economist.</p>
</body>
</html>
This example might be formatted as follows:
18
The ':first-letter' also applies if the first letter is in fact a digit, e.g., the "6" in "67 million
dollars is a lot of money."
The :first-letter pseudo-element applies to block container elements.
The :first-letter pseudo-element can be used with all such elements that contain text, or
that have a descendant in the same flow that contains text. A UA should act as if the
fictional start tag of the first-letter pseudo-element is just before the first text of the
element, even if that first text is in a descendant.
19
Here is an example. The fictional tag sequence for this HTML fragment:
<div>
<p>The first text.
is:
<div>
<p><div:first-letter><p:first-letter>T</...></...>he first text.
The first letter of a table-cell or inline-block cannot be the first letter of an ancestor
element. Thus, in <DIV><P STYLE="display: inline-block">Hello<BR>Goodbye</P>
etcetera</DIV> the first letter of the DIV is not the letter "H". In fact, the DIV does not have
a first letter.
The first letter must occur on the first formatted line. For example, in this fragment:
<p><br>First... the first line does not contain any letters and ':first-letter' does not match
anything (assuming the default style for BR in HTML 4). In particular, it does not match the
"F" of "First."
If an element is a list item ('display: list-item'), the ':first-letter' applies to the first letter in
the principal box after the marker. UAs may ignore ':first-letter' on list items with 'list-styleposition: inside'. If an element has ':before' or ':after' content, the ':first-letter applies to the
first letter of the element including that content.
E.g., after the rule 'p:before {content: "Note: "}', the selector 'p:first-letter' matches the "N"
of "Note".
Some languages may have specific rules about how to treat certain letter combinations. In
Dutch, for example, if the letter combination "ij" appears at the beginning of a word, both
letters should be considered within the :first-letter pseudo-element.
If the letters that would form the first-letter are not in the same element, such as "'T" in
<p>'<em>T..., the UA may create a first-letter pseudo-element from one of the elements,
both elements, or simply not create a pseudo-element.
Similarly, if the first letter(s) of the block are not at the start of the line (for example due to
bidirectional reordering), then the UA need not create the pseudo-element(s).
The following example illustrates how overlapping pseudo-elements may interact. The first
letter of each P element will be green with a font size of '24pt'. The rest of the first
formatted line will be 'blue' while the rest of the paragraph will be 'red'.
p { color: red; font-size: 12pt }
20
21
Animation Properties
Property
Description
CSS Version
@keyframes
animation
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-play-state
Property
Description
CSS Version
background
Background Properties
22
background-attachment
background-color
background-image
background-position
background-repeat
background-clip
background-origin
background-size
Description
CSS Version
border
border-bottom
border-bottom-color
border-bottom-style
border-bottom-width
border-color
23
border-left
border-left-color
border-left-style
border-left-width
border-right
border-right-color
border-right-style
border-right-width
border-style
border-top
border-top-color
border-top-style
border-top-width
border-width
outline
outline-color
outline-style
outline-width
24
border-bottom-leftradius
border-bottom-rightradius
border-image
border-image-outset
border-image-repeat
border-image-slice
border-image-source
border-image-width
border-radius
border-top-left-radius
box-decoration-break
box-shadow
25
Box Properties
Property
Description
CSS Version
overflow-x
overflow-y
overflow-style
rotation
rotation-point
Property
Description
CSS Version
color-profile
opacity
rendering-intent
Color Properties
26
Description
CSS Version
bookmark-label
bookmark-level
bookmark-target
float-offset
hyphenate-after
hyphenate-before
hyphenate-character
hyphenate-lines
hyphenate-resource
hyphens
image-resolution
marks
string-set
27
Dimension Properties
Property
Description
CSS Version
height
max-height
max-width
min-height
min-width
width
Description
CSS Version
box-align
box-direction
box-flex
box-flex-group
box-lines
28
box-ordinal-group
box-orient
box-pack
Property
Description
CSS Version
font
font-family
font-size
font-style
font-variant
font-weight
@font-face
font-size-adjust
font-stretch
Font Properties
29
Description
CSS Version
content
counter-increment
counter-reset
quotes
crop
move-to
page-policy
Property
Description
CSS Version
grid-columns
grid-rows
Grid Properties
30
Hyperlink Properties
Property
Description
CSS Version
target
target-name
target-new
target-position
Property
Description
CSS Version
alignment-adjust
alignment-baseline
baseline-shift
dominant-baseline
Specifies a scaled-baseline-table
Linebox Properties
drop-initial-after-adjust Sets the alignment point of the drop initial for the
primary connection point
drop-initial-after-align
31
drop-initial-beforeadjust
drop-initial-beforealign
drop-initial-size
drop-initial-value
inline-box-align
line-stacking
line-stacking-ruby
line-stacking-shift
line-stacking-strategy
text-height
Property
Description
CSS Version
list-style
List Properties
32
list-style-image
list-style-position
list-style-type
Property
Description
CSS Version
margin
margin-bottom
margin-left
margin-right
margin-top
Property
Description
CSS Version
marquee-direction
marquee-play-count
marquee-speed
marquee-style
Margin Properties
Marquee Properties
33
Multi-column Properties
Property
Description
CSS Version
column-count
column-fill
column-gap
column-rule
column-rule-color
column-rule-style
column-rule-width
column-span
column-width
columns
Property
Description
CSS Version
padding
padding-bottom
Padding Properties
34
padding-left
padding-right
padding-top
Description
CSS Version
fit
fit-position
image-orientation
page
size
Positioning Properties
Property
Description
CSS Version
bottom
clear
35
clip
cursor
display
float
left
overflow
position
right
top
visibility
z-index
Property
Description
CSS Version
orphans
page-break-after
Print Properties
36
page-break-before
page-break-inside
widows
Ruby Properties
Property
Description
CSS Version
ruby-align
ruby-overhang
ruby-position
ruby-span
Property
Description
CSS Version
mark
mark-after
Speech Properties
37
stream
mark-before
phonemes
rest
rest-after
rest-before
voice-balance
voice-duration
voice-pitch
voice-pitch-range
voice-rate
voice-stress
voice-volume
38
Table Properties
Property
Description
CSS Version
border-collapse
border-spacing
caption-side
empty-cells
table-layout
Property
Description
CSS Version
color
direction
letter-spacing
line-height
text-align
text-decoration
text-indent
Text Properties
39
block
text-transform
unicode-bidi
1
2
vertical-align
white-space
word-spacing
hanging-punctuation
punctuation-trim
text-align-last
text-justify
text-outline
text-overflow
text-shadow
text-wrap
40
word-break
word-wrap
Description
CSS Version
transform
transform-origin
transform-style
perspective
perspective-origin
backface-visibility
Transition Properties
Property
Description
CSS Version
transition
transition-property
41
transition-duration
transition-timingfunction
transition-delay
User-interface Properties
Property
Description
CSS Version
appearance
box-sizing
icon
nav-down
nav-index
nav-left
nav-right
nav-up
42
outline-offset
resize
Examples
1. The following example demonstrates how to use background image paroperties of css
<!doctype html>
<html>
<head>
<style>
body
{
background-image:url(e:/images/garden.jpg);
background-repeat:no-repeat;
background-size:200px 200px;
background-position:center center;
background-attachment:fixed;
}
</style>
</head>
<body>
<h1> Provide Text in the body to make the page scrollable </h1>
</body>
</html>
43
2. The following example animates a div element and moves it right and left with
animation properties of css 3
<!doctype html>
<html>
<head>
<style>
div
{
width:100px;
height:100px;
background:red;
position:relative;
animation:mymove 5s 2;
-webkit-animation:mymove 5s infinite; /*Safari and Chrome*/
}
@keyframes mymove
{
from {left:0px;}
to {left:200px;}
}
@-webkit-keyframes mymove /*Safari and Chrome*/
{
from {left:0px;}
to {left:200px;}
}
</style>
44
</head>
<body>
<div></div>
</body>
</html>
3. The following example animates a div element and moves it right then down then left
and finally top with animation properties of css 3
<!doctype html>
<html>
<head>
<style>
div
{
width:100px;
height:100px;
background:red;
position:relative;
animation-name:myfirst;
animation-duration:5s;
animation-timing-function:linear;
animation-delay:2s;
animation-iteration-count:infinite;
animation-direction:alternate;
animation-play-state:running;
/* Firefox: */
-moz-animation-name:myfirst;
45
-moz-animation-duration:5s;
-moz-animation-timing-function:linear;
-moz-animation-delay:2s;
-moz-animation-iteration-count:infinite;
-moz-animation-direction:alternate;
-moz-animation-play-state:running;
/* Safari and Chrome: */
-webkit-animation-name:myfirst;
-webkit-animation-duration:5s;
-webkit-animation-timing-function:linear;
-webkit-animation-delay:2s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:alternate;
-webkit-animation-play-state:running;
/* Opera: */
-o-animation-name:myfirst;
-o-animation-duration:5s;
-o-animation-timing-function:linear;
-o-animation-delay:2s;
-o-animation-iteration-count:infinite;
-o-animation-direction:alternate;
-o-animation-play-state:running;
}
@keyframes myfirst
{
0% {background:red; left:0px; top:0px;}
46
48
to { -o-transform: rotate(360deg);}
}
@-ms-keyframes spin {
from { -ms-transform: rotate(0deg);}
to { -ms-transform: rotate(360deg);}
}
img
{
width:250px;
height:250px;
align:center;
}
img:hover
{
-webkit-animation: spin 5s infinite linear;
-moz-animation: spin 5s infinite linear;
-o-animation: spin 5s infinite linear;
-ms-animation: spin 5s infinite linear;
}
</style>
</head>
<body>
<img src="e:\images\garden.jpg"/>
</body>
</html>
49
5. The following example changes background of the page from red to yellow using
animation properties of css 3
<!doctype html>
<html>
<head>
<style>
body
{
width:100px;
height:100px;
background:red;
position:relative;
animation:mycolor 5s infinite;
-webkit-animation:mymove 5s infinite; /*Safari and Chrome*/
}
@keyframes mycolor
{
from {background: red;}
to {background: yellow;}
}
@-moz-keyframes mycolor /* Firefox */
{
from {background: red;}
to {background: yellow;}
}
@-webkit-keyframes mycolor /* Safari and Chrome */
{
from {background: red;}
to {background: yellow;}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
50
6. The following example demonstrates how to design a page as follows using css
51
#banner {
background: url(images/banner.png) no-repeat right top;
height: 90px;
}
/* NAVIGATION */
#mainNav li {
list-style: none;
display: inline;
}
#mainNav a {
text-decoration: none;
color: #000000;
font-size: 1.1em;
text-transform: uppercase;
border-bottom: 1px dashed #999999;
display: block;
padding: 7px 5px 7px 30px;
background: #E7E7E7 url(images/link.png) no-repeat left center;
}
a#homeLink {
background-image: url(images/home.png);
background-repeat: no-repeat;
background-position: left center;
}
#logo {
display: none;
}
#mainNav ul {
border-top: 1px dashed #999999;
margin-top: 20px;
margin-bottom: 20px;
}
#mainNav a:hover {
background: #B2F511 url(images/go.png) no-repeat left center;
padding-right: 15px;
padding-left: 30px;
font-weight: bold;
52
}
#home #mainNav a#homelink,
#feature #mainNav a#featureLink {
background: #FFFFFF url(images/bg_here.png) no-repeat 95% 50%;
padding-right: 15px;
padding-left: 30px;
font-weight: bold;
}
#home #mainNav a#homelink:hover,
#feature #mainNav a#featureLink:hover {
color: #B2F511;
}
#nav p {
color: #ED6733;
padding-right: 5px;
padding-left: 5px;
}
#nav a {
text-decoration: none;
color: #666666;
}
/* BANNER STYLES */
#banner img {
float: left;
}
#banner ul {
margin: 0px;
padding: 0px;
list-style: none;
}
#banner li {
display: inline;
float: right;
margin-right: 5px;
padding-bottom: .5em; /* to display bottom border on links in IE */
53
}
#sitetools li a {
font-size: 1em;
text-decoration: none;
color: #FFFFFF;
line-height: 2em;
background: #1B3A89;
padding: 5px;
height: 2em;
border: 1px solid #4D69B0;
font-weight: bold;
}
#sitetools li a:hover {
color: #10214E;
background: #DCE5FF;
}
/* MAIN */
#main a {
text-decoration: none;
border-bottom: 1px dashed #B2F511;
color: #152D6A;
}
#main h1 {
color: #152D6A;
margin-top: 15px;
margin-bottom: 5px;
border-bottom: 2px solid #B2F511;
font: normal 2.7em Impact, "Arial Narrow", sans-serif;
text-transform: uppercase;
letter-spacing: 1px;
word-spacing: 5px;
background: url(images/feature_bug.png) no-repeat top right;
}
#main h2 {
font: normal 2em Georgia, "Times New Roman", Times, serif;
margin-top: 15px;
54
margin-bottom: 3px;
color: #152D6A;
}
#main p {
font-size: 1.25em;
margin-bottom: 5px;
}
/* headlines with warnings */
.warning {
background: url(images/warning.png) no-repeat left center;
padding-top: 2px;
padding-left: 30px;
border-bottom: 1px dotted #CCCCCC;
}
/* NEWS */
#news .story {
background: url(images/bg_story.png) repeat-y;
color: #FFFFFF;
padding: 5px 5px;
border-bottom: 1px dashed #AAEB11;
display: block;
text-decoration: none;
line-height: 110%;
}
#news span.title {
font-size: 1.1em;
font-weight: bold;
display: block;
line-height: 120%;
color: #FFCC00;
}
#news a.story:hover {
color: #4A761D;
background: url(images/bg_story_high.png);
}
* html #news a {
height: 1px;
}
55
#news h2 {
background: #B2F511 url(images/bg_newshead.png) no-repeat;
color: #333333;
font-size: 2em;
text-transform: uppercase;
padding-top: 25px;
padding-bottom: 0px;
padding-left: 5px;
}
#news h2 span {
background: url(images/down.png) no-repeat;
position: absolute;
right: 10px;
height: 48px;
width: 48px;
top: 4px;
z-index: 10;
}
/* ADVERTISING */
div.natEx {
text-align: center;
margin-top: 25px;
font-weight: bold;
}
.natEx p {
margin-bottom: 5px;
}
#news a.story:hover span.title {
color: #000000;
}
Create the html file as follows to design the page
<!DOCTYPE html >
<html>
<head>
56
#news
{
float: right;
width: 160px;
}
#nav
{
float: left;
width: 160px;
margin-left: -590px;
}
#legal
{
clear: both;
margin-right: 160px;
padding: 5px 5px 160px 20px;
border-top: 1px dashed #999999;
font-weight: bold;
color: #666666;
}
</style>
</head>
<body id="feature">
<div id="wrapper">
<div id="banner">
<p id="logo"><a href="http://www.cosmofarmer.com/">
58
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem
vel eum iriure.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem
vel eum iriure.</p>
<h2 class="warning">Cast-Iron No-Nos</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem
vel eum iriure.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem
vel eum iriure. </p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem
vel eum iriure.</p>
<h2 class="warning">Clean the Overflow Valve </h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem
vel eum iriure. </p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
60
61
<div id="mainNav">
<ul>
<li><a href="#" id="homeLink">Home</a></li>
<li><a href="#" id="featureLink">Features</a></li>
<li><a href="#">Experts</a></li>
<li><a href="#">Quiz</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">Horoscopes</a></li>
</ul>
</div>
<p>CosmoFarmer.com believes that your privacy is important. All monitoring that
takes place as you visit our site is protected. Infortmation collected
is limited to our network of 9,872 partner affiliates. Your information will only be
shared among them, and as part of our network's anti-spam policy
you will be limited to one e-mail per partner affiliate per day, not to exceed a total
of 9,872 e-mails a day. If you wish to opt out of this program please
call us between the hours of 9:01-9:03am GMT. </p>
<div class="natEx">
<p><a href="http://www.nationalexasperator.com/"><img src="images/ne.png"
alt="National Exasperator" width="97" height="89" /></a></p>
<p><a href="http://www.nationalexasperator.com/">Subscribe to the National
Exasperator Today! </a></p>
</div>
<p> </p>
</div>
<div id="legal">Copyright 2006, CosmoFarmer.com </div>
</div>
</body>
</html>
62
7. The following example demonstrates how to design a page with a form as follows
using css
padding: 0px;
}
br.clear
{
height:1px;
clear:both;
line-height: 1px;
background-color: #00CC33;
}
/* LAYOUT */
#wrapper
{
width: 760px;
border-right-width: 1px;
border-right-style: solid;
border-right-color: #999999;
}
#main
{
border-right: 1px solid #999999;
border-left: 1px solid #999999;
padding: 3px 3px 0 6px;
float: left;
width: 424px;
}
#subNav
64
{
width: 150px;
float: left;
background-color: #FBEF99;
}
#banner
{
background-image: url(images/bg/banner_bg.jpg);
background-repeat: repeat-x;
background-position:
left top;
width: 759px;
border-bottom: 1px solid #999999;
}
#announce
{
float: left;
width: 166px;
border-top: 10px solid #294E56;
margin-top: 3px;
background: url(images/bg/announce_bg.jpg) repeat-x left top;
margin-left: 3px;
line-height: 95%;
margin-right: 3px;
}
#copyright
65
{
clear: both;
margin-left: 150px;
border: 1px solid #999999;
border-right:none;
font-size: 12px;
padding-left: 6px;
}
/* BANNER STYLES */
#background
{
background-image: url(images/bg/banner_flower.jpg);
background-repeat: no-repeat;
background-position: right top;
}
/* image replacement technique */
#banner p.logo
{
background: url(images/logo.gif) no-repeat left top;
height: 70px;
text-indent: -5000px;
}
#nav
{
margin-top: 10px;
margin-bottom: 0px;
66
}
#nav li
{
list-style-type: none;
padding: 0px;
margin: 0;
float: left;
}
#nav a
{
display: block;
font-size: 11px;
color: #D6ECAE;
text-decoration: none;
background-color: #294E56;
padding: 2px 2px 2px 3px;
width: 8em;
margin-left: 2px;
border-right: 1px solid #73AFB7;
border-bottom: 1px solid #73AFB7;
font-weight: bold;
margin-bottom: 2px;
}
#nav a:hover
{
background: #73AFB7;
67
display: block;
text-decoration: none;
color: #102536;
padding: 3px 5px;
border-bottom: 1px solid #14556B;
}
#announce .title
{
font-weight: bold;
display: block;
}
#announce a:hover
{
background-color: #5F9794;
color: #FBEF99
}
#announce ul
{
list-style:none;
}
#announce li
{
display: inline;
}
/* PAGE SPECIFIC STYLES */
/* HOME */
69
background: url(images/bg/side_nav_bg.jpg);
color: #102536;
}
.col2 #announce
{
float: left;
margin-bottom: 10px;
}
.col2 #main
{
float: right;
border-right: none;
width: 573px;
}
.col2 #copyright
{
margin-left: 0px;
}
#main h2
{
font-size: 1.2em;
margin-top: 15px;
color: #666666;
}
#main #subForm p
{
71
margin-top: 10px;
margin-bottom: 10px;
}
#main p.privacy
{
color: #73AFB7;
margin-top: 25px;
margin-bottom: 50px;
font-size: 0.85em;
}
Create a html page as follows for designing the page with a form
<!DOCTYPE html>
<html>
<head>
<link href="global.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]>
<link href="ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<style type="text/css">
#subForm
{
font-size: .8em;
}
#subForm .label
{
72
float: left;
width: 230px;
margin-right: 10px;
text-align: right;
font-weight: bold;
clear: left;
}
#subscribe
{
margin-left: 240px;
background-color: #CBD893;
font-family: "Century Gothic", "Gill Sans", Arial, sans-serif;
}
#refer
{
font-family: "Century Gothic", "Gill Sans", Arial, sans-serif;
}
#name, #email, #comments
{
background-color: #FBEF99;
font-family:"Lucida Console", Monaco, monospace;
font-size: .9em;
width: 300px;
margin-top: -2px;
}
73
#name:focus,
#email:focus,
#comments:focus,
#refer:focus
{
background-color: #FDD041;
}
</style>
</head>
<body id="feature" class="col2">
<div id="wrapper">
<div id="banner">
<div id="background"><p class="logo">CosmoFarmer 2.0</p>
<div id="nav">
<ul>
<li><a href="index.html" id="homeLink">Home</a></li>
<li><a href="/features/index.html" id="featureLink">Features</a></li>
<li><a href="/experts/index.html" id="expertLink">Experts</a></li>
<li><a href="/quiz/index.html" id="quizLink">Quiz</a></li>
<li><a href="/projects/index.html" id="projectLink">Projects</a></li>
<li><a href="/horoscopes/index.html"
id="horoscopeLink">Horoscopes</a></li></ul>
<br class="clear" />
</div>
</div>
<!-- end background -->
74
</div>
<!-- end banner -->
<div id="main">
<h1 id="lead"><span class="section">Sign Up:</span> Reader Subscription Form
</h1>
<form id="subForm" name="subForm">
<p><label for="name" class="label">What is your name?</label>
<input type="text" name="name" id="name" /></p>
<p><label for="email" class="label">What is your email address?</label>
<input type="text" name="email" id="email" /></p>
<p>
<span class="label">Rate your apartment farming skills </span>
<label>
<input name="skill" type="radio" value="novice" />Novice</label>
<label><input name="skill" type="radio" value="intermediate"
/>Intermediate</label>
<label><input name="skill" type="radio" value="advanced"/>Advanced</label>
</p>
<p>
<label for="refer" class="label">Where did you hear about us? </label>
<select name="refer" id="refer">
<option value="null">Select One</option>
<option value="1">Friend</option>
<option value="2">Herban Jungle</option>
<option value="3">Compost Today</option>
<option value="4">Vanity Fair</option>
</select>
75
</p>
<p>
<label for="comments" class="label">Any additional comments? </label>
<textarea name="comments" cols="35" rows="4" id="comments"></textarea>
</p>
<p>
<input type="submit" name="Submit" id="subscribe" value="Subscribe" />
</p>
</form>
<br class="clear" />
<p class="privacy">CosmoFarmer.com believes that your privacy is important.
Information collected at this site is limited to our network of 9,872 partner
affiliates. Your information will only be shared among them, and as part of our
network's anti-spam policy you will be limited to one e-mail per partner affiliate
per day, not to exceed a total of 9,872 e-mails a day. If you wish to opt out of this
program please call us between the hours of 9:01-9:03am GMT.
</p>
</div>
<!-- end main -->
<div id="announce">
<ul>
<li><a href="#"><span class="title">Virgo: It's Your Month</span>Lorem ipsum
dolor site amet.</a></li>
<li><a href="#"><span class="title">Your Feedback </span>Lorem ipsum dolor site
amet.</a></li>
<li><a href="#"><span class="title">This Month's Survey </span>Lorem ipsum
dolor site amet.</a></li>
<li><a href="#"><span class="title">Indoor lawns: sod or seed? </span>Lorem
ipsum dolor site amet.</a></li>
76
<!doctype html>
<html>
<head>
<style>
.threecolumn
{
-moz-column-count:3; /* Firefox */
-webkit-column-count:3; /* Safari and Chrome */
column-count:3;
77
-moz-column-gap:40px; /* Firefox */
-webkit-column-gap:40px; /* Safari and Chrome */
column-gap:40px;
-moz-column-width:200px; /* Firefox */
-webkit-column-width:200px; /* Safari and Chrome */
-ms-column-width:200px;
}
h2
{
-webkit-column-span:1; /* Chrome */
column-span:1;
-ms-column-span:1;
}
</style>
</head>
<body>
<div class="threecolumn">
<h2> This Heading Spans On All Columns In The page This Heading Spans On All
Columns In The page</h2>
This is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3. This is a three column layout created for the
78
page with css 3. This is a three column layout created for the page with css 3. This
is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3. This is a three column layout created for the
page with css 3. This is a three column layout created for the page with css 3. This
is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3. This is a three column layout created for the
page with css 3. This is a three column layout created for the page with css 3. This
is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3. This is a three column layout created for the
page with css 3. This is a three column layout created for the page with css 3. This
is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3. This is a three column layout created for the
page with css 3. This is a three column layout created for the page with css 3. This
is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3. This is a three column layout created for the
page with css 3. This is a three column layout created for the page with css 3. This
is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3. This is a three column layout created for the
page with css 3. This is a three column layout created for the page with css 3. This
is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3. This is a three column layout created for the
page with css 3. This is a three column layout created for the page with css 3. This
is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3. This is a three column layout created for the
page with css 3. This is a three column layout created for the page with css 3. This
is a three column layout created for the page with css 3. This is a three column
layout created for the page with css 3.
</div>
</body>
</html>
79