Cascading Style Sheets
- The purpose of a style sheet is so you can define a single
document that can serve as a basis for creating all your pages.
- If you want to change a color or font, you just change one or two
documents, not all of them. (A website might have hundreds of
pages).
- CSS Styles can be stored directly in an html file, or in a
separate style sheet file (with a .CSS extension)
- To be reuseable, you'll want to define a separate file.
- Within the style sheet you'll want to define the default settings
for common tages (e.g. body, paragraph, heading, links), and some
common divisions.
- to create a new setting for a tag, type in the tag name
with its style settings inside of braces { }.
- to create named divisions, just use div.name followed by braces
containing the settings for that division
- in the example below, div.top creates a divsion class
callled top, that can be later used in an html file by using the class
attribute,
- e.g. <div class = "top" >
- Use the <link> tag to link a .css file to your .html file.
This shoiuld go into the header area.
<LINK rel="stylesheet" type =
"text/css" href=" SimpleCss.css" />
- use /* and */ to comment the code (similar to java)
Click here to view the
example file
SimpleCss.css
body {
font-size:12pt;
font-family: New Times Roman;
color: blue;
line-height: 16pt;
background-image: url("samplebackground.jpg");
background-size: 100%;
}
p{
margin-left: 24pt;
margin-right: 24pt;
}
h1 {
font-size:36pt;
font-family:Arial;
color:black;
}
h2 {
font-size:24pt;
font-family:Arial;
color:black;
}
a {
color:blue;
}
a:link {
color:yellow;
}
a:visited {
color:magenta;
}
div {
overflow:auto;
outline-style:double;
margin: 50px;
position: absolute;
}
div.top {
top:10px;
left:10px;
background-color:teal;
width:1000px;
height:100px;
text-align:center;
color:black;
}
div.bottom {
top:670px;
left:10px;
background-color:teal;
width:1000px;
height:100px;
text-align:center;
color:black;
}
div.left {
top:115px;
left:10px;
background-color:aqua;
width: 100px;
height: 550px;
text-align:left;
}
div.right {
top:115px;
left:910px;
background-color:aqua;
width:100px;
height: 550px;
text-align:right;
}
div.center {
top:115px;
left:115px;
background-color:white;
width: 790px;
height: 550px;
text-align:left;
}
htmlsamplecss.html
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE> Sample HTML Page with a CSS</TITLE>
<LINK rel="stylesheet" type = "text/css" href=" SimpleCss.css" />
</HEAD>
<BODY>
<DIV class="top">
<h1>Gettysburg Address</h1>
</DIV>
<DIV class="bottom">
</DIV>
<DIV class="left">
</DIV>
<DIV class="right">
</DIV>
<DIV class="center">
<p>Four score and seven years ago our fathers brought forth on
this continent a new nation,
conceived in liberty, and dedicated to the proposition that all men are
created equal.</p>
<p>
Now we are engaged in a great civil war, testing whether that nation,
or any nation,
so conceived and so dedicated, can long endure. We are met on a great
battle-field of that war.
We have come to dedicate a portion of that field, as a final resting
place for those who here gave
their lives that that nation might live. It is altogether fitting and
proper that we should do this.
</p>
<p>
But, in a larger sense, we can not dedicate, we can not consecrate, we
can not hallow this ground.
The brave men, living and dead, who struggled here, have consecrated it,
far above our poor power to add or detract. The world will little note,
nor long remember what we say here,
but it can never forget what they did here. It is for us the living,
rather,
to be dedicated here to the unfinished work which they who fought here
have thus far so nobly advanced. </p>
<p>
It is rather for us to be here dedicated to the great task remaining
before us that from these honored
dead we take increased devotion to that cause for which they gave the
last full measure of devotion
that we here highly resolve that these dead shall not have died in vain
that this nation, under God,
shall have a new birth of freedom and that government of the people, by
the people,
for the people, shall not perish from the earth.
</DIV>
</BODY>
</HTML>