CSS Cascading Style Sheets
CSS Cascading Style Sheets
property_n: value_n;"
<!DOCTYPE html>
<html>
<head>
<title>HTML Inline CSS</title>
</head>
<body>
<p style="color:red;">web
programming</p>
<p style="fontsize:20px;">Robert
Sebesta</p>
<p
style="color:Yellow;">OOP</p
>
<p style="color:blue;fontsize:20px;">Robert
<!DOCTYPE html>
<html>
<head>
<style>
p{
text-align: center;
color: red;
}
</style>
</head>
<body>
<p>Programming the world wide
web</p>
</body>
</html>
Sample.css
body {
background-color: cyan;
}
h1 {
color: blue;
text-align: center;
}
p{
color: green;
text-align: right;
}
Welcome.html
<!DOCTYPE html>
<html lang = "en">
<head>
<title>externalStyle.html</title>
<link rel = "stylesheet type =
"text/css href =
"D:\sample.css" />
</head>
<body>
<h1>Welcome</h1>
<p>
Faculty of Science and TechnologyFST
</p>
</body>
</html>
Assignment
<html xmlns =
"http://www.w3.org/1999/xhtml">
<head>
<title> Our first document </title>
<style>
h1, h3 { font-size: 10pt ;}
p { font-size: 25pt ;}
</style>
</head>
<body>
<h1>welcome</h1>
<h2>welcome</h2>
<p>welcome</p>
<h3>welcome</h3>
</body>
</html>
Class Selectors
Used to allow different occurrences of the same
tag to use different style specifications.
A style class has a name, which is attached to
the tags name with a period.
The class you want on a particular occurrence of
a tag is specified with the class attribute of the
tag.
For example:
p.normal {property-value list}
p.warning {property-value list}
Generic Selectors
A generic class can be defined if you want a
style to apply to more than one kind of tag.
A generic class must be named, and the name
must begin with a period without a tag name in
its name.
For Example:
.sale{ }
Use it as if it were a normal style class
<h1 class = sale"> This Tuesday is a holiday
</h1>...
<html xmlns =
"http://www.w3.org/1999/xhtml">
<head>
<title> Our first document </title>
<style>
.urgent {
font-weight:bold; color:red;
}
</style>
</head>
<body>
<p class = "urgent"> Urgent Circular </p>
<h1> This is h1</h1>
</body>
</html>
Id Selectors
An id selector allow the application of a style to one
specific element.
The general form of an id selector is as follows :
#specific-id {property-value list}
Example:
#section14 {font-size: 20} specifies a font
size of 20 points to the element
<h2 id =section14> Alice in
wonderland</h2>
Universal selector
The universal selector, denoted by an asterisk(*), which
applies style to all elements in the document.
For example:
*{property-value list}
<html xmlns =
"http://www.w3.org/1999/xhtml">
<head>
<title> Our first document </title>
<style>
*{color: red;}
</style>
</head> <body>
<h1> Twinkle twinkle little star</h1>
<h2> how I wonder </h2>
<h3>what you are ???</h3>
<h4>up above the world so
high</h4>
<h5> like a diamond</h5>
<h6> in the sky.</h6>
</body>
</html>
Pseudo Classes
Pseudo classes are styles that apply when something
happens, rather than because the target element simply
exists.
Names of pseudo classes begin with colons hover classes
apply when the mouse cursor is over the element focus
classes apply when an element has focus
i.e. the mouse cursor is over the element and the left
mouse button is clicked.
<html xmlns =
"http://www.w3.org/1999/xhtml">
<head> <title> Checkboxes </title>
<style type = "text/css">
input:hover {color: green;}
input:focus {color: red;}
</style> </head> <body>
<form action = ""> <p>
Your name:
<input type = "text" />
</p> </form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HTML Internal CSS</title>
<style type="text/css">
.red{
color: red;
}
.thick{
font-size:20px;
}
.green{
color:blue;
}
</style>
</head>
<body>
<p class="red">Programming
WWW</p>
<p class="thick">Robert
Sebesta</p>
<p class="green">OOP</p>
<p class="thick green">Robert
URL values:
URL property values use a form that is slightly
different from references to URLs in links.
The actual URL, which can be either absolute or relative,
is placed in parentheses and preceded by url,
url(protocol://server/pathname)
Colors :
Color name rgb(n1, n2, n3)
Hex form: #B0E0E6 , stands for powder blue color.
Font properties
Font-family
The font-family property is used to specify a list of font
name.
The browser will use the first font in the list that it
supports.
For example:
Generic
fonts:
font-family:
Arial, Helvetica, Courier
They can be specified as the font family value
serif, sans-serif, cursive, fantasy, and monospace
(defined in CSS).
Browser has a specific font defined for each generic
name.
Font-size
Possible values: a length of a number or a name, such
as smaller, xx-large, medium , large etc.
Different browsers can use different relative value for
the font-size.
Font-variant
The default value of the font-variant property is normal,
which specifies the usual character font.
This property can be set to small-caps to specify
small /capital characters.
Font-style
The font-style property is most commonly used to
specify style
Eg: font-style: italic
Font-weights
The font-weight property is used to specify the degree of
boldness.
Eg: font-weight : bold
Sample.html
a.css file
<html
xmlns="http://www.w3.org/1999/x
html">
<head>
<title>CSS Example</title>
<link rel="stylesheet"
type="text/css"
href="D:\a.css" />
</head>
<body>
<h1>CSS</h1>
<p>This is Cascading style
sheet</p>
<p class="important">This
paragraph demonstrates the use
of the <code>class</code>
attribute.</p>
</body>
body {
font-family:arial, verdana,
sans-serif; backgroundcolor:green;
}
h1 {
color:red;
font-size:22pt;}
p{
color:blue;
font-size:18pt;}
p.important {
color:red;font-size:10pt;
background-color:#B0E0E6 ;
padding:5px;margin:15px;
width:40em;}
output
Text Decoration
The text-decoration property is used to specify some
special features of the text.
The available values are line-through, overline,
underline, and none, which is the default.
Many browsers underline links.
Eg:line-through, overline, underline, none
Letter-spacing
Value is any length property value controls amount
of space between characters in text
Eg: 3px
a.css file
p.one {font-family:arial, verdana, sans-serif;}
p.two {font-family:'times new roman', serif;}
p.three {font-family:courier, 'courier new',
monospace;}
p.four {font-family:arial, cursive;}
p.five {font-family:Cottonwood, Studz, fantasy;}
Sample.html file
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Example</title>
<link rel="stylesheet" type="text/css" href="D:\a.css" /> </head>
<body>
<p class="one">The first paragraph of text should be displayed in a
sans-serif font.</p>
<p class="two">The second paragraph of text should be displayed in a
serif font.</p>
<p class="three">The third paragraph of text should be displayed in a
monospaced font.</p>
<p class="four">The fourth paragraph of text should be displayed in a
cursive font.</p> <p
output
Sample.html
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSS Example</title>
<link rel="stylesheet" type="text/css"
href="d:\a.css" /> </head>
<body>
<h1>Lengths</h1>
<p class="px">The length used here is 12
px</p> <p class="pt">The length used
here is 12
pt</p>
<p class="pc">The length used here is 2
pc</p> <p class="in">The length used
here is
0.5in</p>
<p class="cm">The length used here is
1cm</p> <p class="mm">The length
used here is
12mm</p>
<p class="em">The length used here is
1.5em</p> <p class="ex">The length
a.css file
p {font-family:arial;
font-size:12pt;}
/* lengths */
p.px {font-size:12px;}
p.pt {font-size:12pt;}
p.pc {font-size:2pc;}
p.in {font-size:0.5in;}
p.cm {font-size:1cm;}
p.mm {font-size:12mm;}
p.em {font-size:1.5em;}
p.ex {font-size:1.5ex;}
List properties:
It is used to specify style of bullets or sequencing
values in list items. The list-style-type of Unordered
lists can be set to disc,circle,square or none.
<html>
</head><body>
<h3> Name of subjects offered</h3>
<ul style = "list-style-type: square">
<li> web programming</li>
<li> Data structures</li>
<li> Compilers design </li>
</ul>
<h3> Name of subjects offered</h3>
<ul>
<li style = "list-style-type: disc">
web programming </li>
<li style = "list-style-type: square">
Data structures</li>
<li style = "list-style-type: circle">
Compilers design </li>
</ul></body>
</html>
Property value
Decimal
upper-alpha
lower-alpha
upper-roman
lower-roman
Sequence type
Arabic numerals
Uc letters
Lc letters
Uc Roman
Lc Roman
Assignment
1cm;
10pt;
10px;
none;
Definition:
Using this attribute we can define or set the space
between each letters.
It takes the following values.
a) cm : You can set the value in centimeters as 1cm etc...
b) px : You can set the value in pixels as 1px or 10px etc...
c) pt : You can set the value in points as 1pt or 2pt etc
d) norm : on setting norm, normal / default word spacing
will be taken
Ex: <font style="letter-spacing: 1cm;">
1cm;
10pt;
10px;
none;
p.small{
line-height:10px;
}
p.big{
line-height:200%;
}
p.big{
line-height:30px;
}
Normal:
Number:
Anormallineheight.Thisisdefault
Anumberthatwillbemultipliedwiththecurrentfontsize
tosetthelineheight
Length:
Afixedlineheightinpx,pt,cm,etc.
%: Alineheightinpercentofthecurrentfontsize
Alignment of Text:
The textalign property has the possible values, left (the default),
center, right.
h1{
text-align:center;
}
h2{
text-align:left;
}
h3{
text-align:right;
}
<!DOCTYPE html>
<! First Progam-- >
<html lang=en>
<head>
<title> text alignment </title>
<meta charset="utf-8"/>
<style type = "text/css">
p{font-size: 20px;font-style: oblique;color: green;text-align: right;}
</style>
</head>
<body>
<p>
The tulip is lily family.
</p>
</body>
</html>
Alignment of Text
Property: float
<!DOCTYPE html>
<html lang=en>
<head>
<title> text alignment </title>
<meta charset="utf-8"/>
<style type = "text/css">
img {float: right;}
</style>
</head>
<body>
<p>
<img src="C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg",height=
200, width=200,alt="failed to upload"/>
The tulip is a Eurasian and North African genus of perennial, bulbous
plants in the lily family.
It is an herbaceous herb with showy flowers, of which around 75 wild
species are currently accepted.The genus's native range extends west to
the Iberian Peninsula, through North Africa to Greece, the Balkans, Turkey,
throughout the Levant (Syria, Israel, Palestinian Territories, Lebanon,
Jordan) and Iran, north to Ukraine, southern Siberia and Mongolia, and
east to the Northwest of China. The tulip's centre of diversity is in the
Pamir, Hindu Kush, and Tien Shan mountains. It is a common element of
steppe and winter-rain Mediterranean vegetation. A number of species
and many hybrid cultivars are grown in gardens or as potted plants.
</p>
Output
Color: Table
Black
silver
gray
white
maroon
red
purple
fuchia
000000
C0C0C0
808080
FFFFFF
800000
FF0000
800080
FF00FF
green 008000
lime 00FF00
olive 808000
yellow
FFFF00
navy 000080
blue 0000FF
teal
008080
aqua 00FFFF
EX:
<style type = text/css>
th.red {color: red}
th.orange {color: orange}
</style>
<table border = "5">
<tr>
<th class = "red"> Apple </th>
<th class = "orange"> Orange </th>
<th class = "orange"> Screwdriver </th>
</tr>
</table>
The background-color property specifies the
background color of elements
<!DOCTYPE html>
<! First Progam-- >
<html lang=en>
<head>
<title> text alignment </title>
<meta charset="utf-8"/>
<style type = "text/css">
p.display{font-size: 20px;font-style: oblique;color:
green;background-color:magenta;}
</style>
</head>
<body>
<p class="display">
The tulip is lily family.
</p>
</body>
</html>
Box Model:
The amount space between the content of an element
and its border is padding.
Space between the border and an adjacent element
known as margin.
Borders:
Everyelementhasaborder-style property.
ItControlswhethertheelementhasaborderandthestyleoftheborder.
Thestylesofoneofthefoursidesofanelementcanbesetwith
border-style values:none, dotted, dashed, and double
border-widththin, medium (default), thick,oralengthvaluein
pixels.
Borderwidthcanbespecifiedforanyofthefourborders(e.g., bordertop-width)
bordercoloranycolor,Bordercolorcanbespecifiedforanyofthe
fourborders(e.g., border-topcolor)
<tr>
<th> </th>
<th> Fruits </th>
<html xmlns =
"http://www.w3.org/1999/xhtml"><th> vegetables </th>
<th> Carbohydrates </th>
<head> <title> Table borders
</tr> <tr>
</title>
<th> Breakfast </th>
<style type = "text/css">
<td> 0 </td>
table {border-top-width: medium;<td> 1 </td>
border-bottom-width: thick;
<td> 0 </td>
border-top-color: red;
</tr> <tr>
border-bottom-color: green;
<th> Lunch </th>
<td> 1 </td>
border-top-style: dotted;
<td> 0 </td>
border-bottom-style: dashed;
<td> 0 </td> </tr> <tr>
}
p {border-style: dashed; border- <th> Dinner </th>
<td> 0 </td>
width: thin;
<td> 0 </td>
border-color: green
<td> 1 </td>
} </style> </head>
</tr>
<body> <table border = "5"> </table> <p>
<caption> Diet chart </caption> If you strictly follow the chart you can
easily lose weight.
</p> </body>
</html>
Margin
Thespacebetweentheborderofanelementanditsneighbor
element.
Themarginsaroundanelementcanbesetwithmargin-left,etc.-
justassignthemalengthvalue
<imgsrc="c210.jpg"style="float:right;margin-left:0.35in;
margin-bottom:0.35in"/>
Paddingthedistancebetweenthecontentofanelementandits
border
<html xmlns =
"http://www.w3.org/1999/xhtml">
<head><title> Margins and
Padding
</title><style type = "text/css">
p.one {margin: 0.2in;
padding: 0.2in;
background-color: #C0C0C0;
border-style: solid;
}
p.two {margin: 0.1in;
padding: 0.3in;
background-color: #C0C0C0;
border-style: solid;
}
p.three {margin: 0.3in; padding:
0.1in;
background-color: #C0C0C0;
border-style: solid; }
p.four {margin:0.4in;
background-color: #C0C0C0;}
p.five {padding: 0.4in;
background-color: #C0C0C0;
}
<body>
<p> Here is the first line. </p>
<p class = "one">
Style sheets allow you to impose a
standard style on a whole document,
or even a whole
collection of documents <br />
[margin = 0.2in, padding = 0.2in]
</p>
<p class = "two">
Style sheets allow you to impose a
standard style on a whole document,
or even a whole
collection of documents. <br />
[margin = 0.1in,
padding = 0.3in]
</p>
<p class = "three">
Style sheets allow you to impose a
standard style on a whole document,
or even a whole
collection of documents <br />
[margin = 0.3in,