Professional Documents
Culture Documents
Cascading Style Sheets (CSS) offer much greater control over type
characteristics that does the <font> element. You can use standard type
conventions, such as using point or pixel sizes, setting leading and specifying
indents and alignment.
CSS is based on rules that select on HTML element and declare style
characteristics for the element. You can state sets of rules, known as style
sheets, in the head section of an HTML document or include them in a
separate document known as external style sheet. Use external style
sheets to set rules when working with a number of HTML documents.
Style sheet rules are easy to interpret. The style rules are contained in the
<STYLE> element in the document’s head section.
Example:
<head><title>Sample Document</title>
<style>
p {color: blue; font-size: 24 pt}
</style>
</head>
This rule sets all <p> elements in the document to blue 24 pt text. Style
rules are composed of two parts: a Selector and a declaration. The selector
determines the element to which the rule is applied. The declaration details
the exact property values.
Example:
H1 { color: red}
H1 ---- selector
Color: red ----- declaration
You must include all CSS rules within a <style> element, or define them
using a style attribute.
Example:
Alternately, you can define the style for a single <h1> element using the
STYLE attribute.
Placing style sheets in an external document lets you specify rules for
different HTML documents. This is an easy and powerful way to use
stylesheets.
Example:
/*StyleSheet #1*/
body{color:red}
h1{color:green}
h2{color:green; border: solid blue}
Note: The stylesheet file contains no HTML code, only css style rules. To link
to this external style sheet, add the <link> element within the head section
of any HTML files.
Example:
<head>
<title> Sample Document </title>
<link href=”style1.css” rel=”stylesheet”>
</head>
The power in css comes from the different methods of selecting elements.
You can choose from a variety of selection methods including:
More complex selection involves the creation of artificial division, using two
elements designed expressly for css:
Example:
<style type=”text/css”>
h1,h2{color:green}
</style>
Selecting By Context
<style type=”text/css”>
h1 I{color:blue}
</style>
Note:
The class attribute lets you write rules and then apply them to groups
of elements that you have classified. Basically, the class attribute lets you
define your own tags and then apply them anywhere you want.
Ex:
.Quote{color:red}
<style type=”text/css”>
.Quote{color:red}
</style>
The <DIV> element lets you specify logical divisions within a document that
have their own name and style properties. <DIV> is a block level element
that contains a leading and trailing carriage return. You can use the <div>
element with the class attribute to create customized block level element.
Example:
The <span> element lets you specify inline elements within the document
that have their own name and properties. Place inline elements within a line
of text, like the <b> or <i> elements.
Examples of CSS:
1. The HTML file below links to an external style sheet with the <link>
tag:
<html>
<head>
<link rel="stylesheet"
<body>
</body>
</html>
This header is 36 pt
This header is blue
This paragraph has a left margin of 50 pixels
2. The HTML file below links to an external style sheet with the <link> tag:
<html>
<head>
<link rel="stylesheet" type="text/css"
href="ex2.css" />
</head>
<body>
<p><a href="http://www.w3schools.com"
target="_blank">This is a link</a></p>
</body>
</html>
<html>
<head>
<style type="text/css">
body {background-color: yellow}
h1 {background-color: #00ff00}
h2 {background-color: transparent}
p {background-color: rgb(250,0,255)}
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<style type="text/css">
body
{
background-image:
url('bgdesert.jpg')
}
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<style type="text/css">
body
{
background-image: url('smiley.gif');
background-repeat: no-repeat;
background-position: 30% 20%;
}
</style>
</head>
<body>
</body>
</html>
The CSS background properties allow you to control the background color of
an element, set an image as the background, repeat a background image
vertically or horizontally, and position an image on a page.
W3C: The number in the "W3C" column indicates in which CSS recommendation the
property is defined (CSS1 or CSS2).
bottom center
bottom right
x% y%
xpos ypos
background- Sets if/how a repeat
repeat background image repeat-x
will be repeated repeat-y
no-repeat
<html>
<head>
<style type="text/css">
h1 {color: #00ff00}
h2 {color: #dda0dd}
p {color: rgb(0,0,255)}
</style>
</head>
<body>
<h1>This is header 1</h1>
<h2>This is header 2</h2>
<p>This is a paragraph</p>
</body>
</html>
<html>
<head>
<style type="text/css">
span.highlight
{
background-color:yellow
}
</style>
</head>
<body>
<p>
<span class="highlight">This is a text.</span> This is a text.
This is a text. This is a text. This is a text. This is a text.
This is a text. This is a text. This is a text. <span
class="highlight">This is a text.</span>
</p>
</body>
</html>
<html>
<head>
<style type="text/css">
p.small {line-height: 90%}
p.big {line-height: 200%}
</style>
</head>
<body>
<p>
This is a paragraph with a standard line-height.
The default line height in most browsers is about 110% to 120%.
This is a paragraph with a standard line-height.
This is a paragraph with a standard line-height.
</p>
<p class="small">
This is a paragraph with a smaller line-height.
This is a paragraph with a smaller line-height.
This is a paragraph with a smaller line-height.
This is a paragraph with a smaller line-height.
</p>
<p class="big">
This is a paragraph with a bigger line-height.
This is a paragraph with a bigger line-height.
This is a paragraph with a bigger line-height.
This is a paragraph with a bigger line-height.
</p>
</body>
</html>
<html>
<head>
<style type="text/css">
h1 {text-align: center}
h2 {text-align: left}
h3 {text-align: right}
</style>
</head>
<body>
<h1>This is header 1</h1>
<h2>This is header 2</h2>
<h3>This is header 3</h3>
</body>
</html>
<html>
<head>
<style type="text/css">
h1 {text-decoration: overline}
h2 {text-decoration: line-through}
h3 {text-decoration: underline}
a {text-decoration: none}
</style>
</head>
<body>
<h1>This is header 1</h1>
<h2>This is header 2</h2>
<h3>This is header 3</h3>
<p><a href="http://www.w3schools.com/default.asp">This is a
link</a></p>
</body>
</html>
<html>
<head>
<style type="text/css">
p {text-indent: 1cm}
</style>
</head>
<body>
<p>
This is some text in a paragraph
This is some text in a paragraph
This is some text in a paragraph
This is some text in a paragraph
This is some text in a paragraph
This is some text in a paragraph
</p>
</body>
</html>
<html>
<head>
<style type="text/css">
p.uppercase {text-transform: uppercase}
p.lowercase {text-transform: lowercase}
p.capitalize {text-transform: capitalize}
</style>
</head>
<body>
<p class="uppercase">This is some text in a paragraph</p>
</html>
<html>
<head>
<style type="text/css">
div.one
{
direction: rtl
}
div.two
{
direction: ltr
}
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<style type="text/css">
p
{
word-spacing: 30px
}
</style>
</head>
<body>
<p>
This is some text. This is some text.
</p>
</body>
</html>
<html>
<head>
<style type="text/css">
p
{
white-space: nowrap
}
</style>
</head>
<body>
<p>
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>
</body>
</html>
The CSS text properties allow you to control the appearance of text. It is
possible to change the color of a text, increase or decrease the space
between characters in a text, align a text, decorate a text, indent the first
line in a text, and more.
text-shadow none
color
length
unicode-bidi normal
embed
bidi-override
The CSS font properties allow you to change the font family, boldness, size,
and the style of a text.
Note: In CSS1 fonts are identified by a font name. If a browser does not
support the specified font, it will use a default font.
200
300
400
500
600
700
800
900
Examples:
<html>
<head>
<style type="text/css">
h3 {font-family: times}
p {font-family: courier}
</style>
</head>
<body>
<p>This is a paragraph</p>
</body>
</html>
<html>
<head>
<style type="text/css">
h1 {font-size: 150%}
h2 {font-size: 130%}
p {font-size: 100%}
</style>
</head>
<body>
<p>This is a paragraph</p>
</body>
</html>
<html>
<head>
<style type="text/css">
h1 {font-style: italic}
h2 {font-style: normal}
p {font-style: oblique}
</style>
</head>
<body>
<p>This is a paragraph</p>
</body>
</html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
a text, but with the CSS border properties we can create borders with
nice effects, and it can be applied to any element.
W3C: The number in the "W3C" column indicates in which CSS recommendation the
property is defined (CSS1 or CSS2).
Examples:
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<p>Some text</p>
</body>
</html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<style type="text/css">
p.one
border-style: solid;
border-color: #0000ff
p.two
border-style: solid;
p.three
border-style: solid;
p.four
border-style: solid;
</style>
</head>
<body>
</body>
</html>
Note: Netscape and IE give the body tag a default margin of 8px.
Opera does not! Instead, Opera applies a default padding of 8px, so if
one wants to adjust the margin for an entire page and have it display
correctly in Opera, the body padding must be set as well!
W3C: The number in the "W3C" column indicates in which CSS recommendation the
property is defined (CSS1 or CSS2).
Examples
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<style type="text/css">
p.rightmargin
margin-right:25%
</style>
</head>
<body>
</body>
</html>
CSS List
The CSS list properties allow you to place the list-item marker, change
between different list-item markers, or set an image as the list-item
marker.
The CSS list properties allow you to place the list-item marker, change
between different list-item markers, or set an image as the list-item
marker.
Examples:
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<ul class="disc">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="circle">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="square">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="none">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<ol class="decimal">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="lroman">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="uroman">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="lalpha">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
<ol class="ualpha">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ol>
</body>
</html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<ul class="disc">
<li>Disc type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="circle">
<li>Circle type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="square">
<li>Square type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="none">
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="decimal">
<li>Decimal type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="decimal-leading-zero">
<li>Decimal-leading-zero type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="lower-roman">
<li>Lower-roman type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="upper-roman">
<li>Upper-roman type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="lower-alpha">
<li>Lower-alpha type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="upper-alpha">
<li>Upper-alpha type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="lower-greek">
<li>Lower-greek type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="lower-latin">
<li>Lower-latin type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="upper-latin">
<li>Upper-latin type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="hebrew">
<li>Hebrew type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="armenian">
<li>Armenian type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="georgian">
<li>Georgian type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="cjk-ideographic">
<li>Cjk-ideographic type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="hiragana">
<li>Hiragana type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="katakana">
<li>Katakana type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="hiragana-iroha">
<li>Hiragana-iroha type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ul class="katakana-iroha">
<li>Katakana-iroha type</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
<html>
<head>
<style type="text/css">
ul.inside
list-style-position: inside
ul.outside
list-style-position: outside
</style>
</head>
<body>
<ul class="inside">
</ul>
<ul class="outside">
</ul>
</body>
</html>
<html>
<head>
<style type="text/css">
ul
</style>
</head>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
</body>
</html>
CSS Table
The CSS table properties allow you to set the layout of a table.
The CSS table properties allow you to set the layout of a table.
W3C: The number in the "W3C" column indicates in which CSS recommendation the
property is defined (CSS1 or CSS2).
Examples:
<html>
<head>
<style type="text/css">
table.one
table-layout: automatic
table.two
table-layout: fixed
</style>
</head>
<body>
<tr>
<td width="20%">1000000000000000000000000000</td>
<td width="40%">10000000</td>
<td width="40%">100</td>
</tr>
</table>
<br />
<tr>
<td width="20%">1000000000000000000000000000</td>
<td width="40%">10000000</td>
<td width="40%">100</td>
</tr>
</table>
</body>
</html>
<html>
<head>
<style type="text/css">
table
border-collapse: separate;
empty-cells: show
</style>
</head>
<body>
<table border="1">
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td></td>
</tr>
</table>
</body>
</html>
<html>
<head>
<style type="text/css">
table.coll
border-collapse: collapse
table.sep
border-collapse: separate
</style>
</head>
<body>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
<br />
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
</body>
</html>
<html>
<head>
<style type="text/css">
table.one
border-collapse: separate;
border-spacing: 10px
table.two
border-collapse: separate;
</style>
</head>
<body>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
<br />
<tr>
<td>Cleveland</td>
<td>Brown</td>
</tr>
<tr>
<td>Glenn</td>
<td>Quagmire</td>
</tr>
</table>
</body>
</html>
<html>
<head>
<style type="text/css">
caption
caption-side:bottom
</style>
</head>
<body>
<table border="1">
<caption>This is a caption</caption>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
</body>
</html>