CSS Example
CSS Example
blockquote {
background: ffff00;
color: black;
}
You can group HTML Selectors together:
h2, h3, h4, h5, h6 {
font-family: "Arial", "sans-
serif";
font-style: italic;
font-size: large;
}
Style Type Placement Affected How?
Inline As part of an HTML tag placed in The specific tag the style is
aka: Local Style between the <body> tags attached to in that occurrence.
</p>
<p>
Then took the other, as just as fair, <br/>
and having perhaps the better claim <br/>
because it was grassy and wanted wear; <br/>
though as for that, the passing there <br/>
had worn them really about the same, <br/>
</p>
Poem by:
Robert Frost
</body>
</html>
Suppose we add 2 paragraphs, whose styles are not
defined in any way:
Letsadd a generic style for the <p> tag. This is the
result:
Resultdemonstrates the
Order of priority.
<html>
<head>
<style>
p
{
background-color:yellow;
}
</style>
</head>
<body>
Lets take the styles defined in the heading out into
an external sheet called styles.css
a) styles.css:
p{
background-color:yellow;
}
b) head:
<head>
<link rel="stylesheet" href="styles.css"/>
</head>
To open a comment, use: /*
To close a comment, use */
Wherever possible, place your styles in external
style sheets
Take advantage of the power of CSS to have
control over an entire Web site
You can create classes of styles that will create
different effects for the HTML tag it is associated
with.
They can be applied to any HTML tag and can be
named anything you want.
The class name always begins with a period ( . ).
It is a good idea to keep the class name simple and
descriptive, based on how you will use the class in
your document.
There are two types of classes that you can
create:
a) Independent
b) Dependent
Can be used with any HTML tag.
As in the example below, you can see that the class,
“.supersize” is independent and can be used with
any HTML tag.
<div class="italic">
<p class="backcolor">
<html>
<head>
<style type="text/css">
p { color: green;} /* this is a type selector */
p.warning {font-size: 16pt; color: blue; }
.myclass { color: red;}
</style>
</head>
<body>
<h1 class='myclass' >The header has now a red color</h1>
<p>This paragraph has no class selector, but a type selector</p>
<div class='myclass'>
Text inside the div tag is red.
<p class='warning'>paragraph inside div element is now blue and 16 pt.</p>
</div>
</body>
</html>
In one instance of the <p> tag, we use the independent
class named “underline”, and in the other, we use the
dependent class named “noindent”
<html> } <p>Creating web pages for a living is a great outlet for
those with creative talents. </p>
<head> .fish2 {
<p>The pay isn't so bad either! </p>
<title>About Our Company</title> list-style-image: url(fish2.gif);
<style> }
<h2>My Hobbies</h2>
<!-- p.noindent {
<ol>
h1 { text-indent: 0%;
<li>I like to Fish</li>
color: blue; }
<ul>
} .green {
<li>Salmon</li>
p { color: green;
<li>Muramba</li>
color: red; }
</ul>
background: aqua; .underline{
<li>I like to Fish</li>
text-indent: 30px; text-decoration: underline;
<ul>
} }
<li class="fish1">Salmon</li>
h2, h3, h4, h5, h6 .normal {
<li class="fish2">Flounder</li>
{ font-style: normal;
</ul>
font-family: "Arial", "Sans-Serif"; }
<li>I like to cook. Check out this great cooking site.
font-style: italic; .italic {
</li>
font-size: large; font-style: italic;
<a href="http://www.outlawcook.com/">Simple
color: green font-weight: bold; Cooking</a>
} } </ol>
</style> <p>
<h2> And finally, an embedded style sheet</h2>
</head> </p>
<body> </body>
Vertical menu
Adding image hyperlinks
Putting span elements
Positioning a paragraph on the page
Adding a background color to a paragraph
<html> font-weight: normal; </div>
{ background:url(img_navsprites.gif) 0 0; </div>
margin: 5px; <li><a href="#news">News</a></li> <p>'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in
this world haven't had the advantages that you've had.'</p>
border: 1px solid #ffffff; <li><a href="#contact">Contact</a></li>
</div>
} <li><a href="#about">About</a></li>
</body>
div.img a:hover img {border: 1px solid #0000ff;} </ul>
</html>
div.desc <div class="img">