Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
SHEETS (CSS)
Style Sheet Basics
Formatting to a particular piece of
content in a document
Syntax :
selector { property1 : value1; ……
propertyn : valuen ; }
Example :
body { background-color : black;
color : pink ; }
h1 { text-decoration : underline; font-family : Impact ;
color : pink ; }
Types of Style Sheets
(Adding Style to a Document)
Example :
--------------------------------------------
<html>
<head>
<title> Embedded Style Sheet </title>
<style>
h1 { text-decoration : underline; font-family : Impact ;
color : pink ; }
</style>
</head>
<body>
<h1> CSS Embedded Style Sheet </h1>
</body>
</html>
---------------------------------------------
Linked / External Style Sheet
Using <LINK> element in <HEAD> element, link a .css file to apply
external style to a document
Example :
---------------------------------------------
- CSSDemo.css
h1 { text-decoration : underline;
font-family : Impact ;
color : pink ; }
---------------------------------------------
<html>
<head>
<title> Linked Style Sheet </title>
<LINK REL=“STYLESHEET” HREF=“CSSDemo.css” />
</head>
<body>
<h1> CSS Linked Style Sheet </h1>
</body>
</html>
---------------------------------------------
Inline Style Sheet
Using the style attribute exactly where the style needs to be
applied.
Example :
---------------------------------------------
<html>
<head>
<title> Inline Style Sheet </title>
</head>
<body>
<h1 style=“text-decoration : underline;
font-family : Impact ;
color : pink ; “ > CSS Inline
</h1>
</body>
</html>
---------------------------------------------
Ways to apply Style Rules
Element
ID Rules
Class Rules
Element
Syntax :
element name { property1 : value1; ……
propertyn : valuen ; }
Example :
body { background-color : black;
color : pink ; }
h1, h2, h3 { text-decoration : underline; font-
family : Impact ;
color : pink ; }
ID Rules
Syntax :
#IDName { property1 : value1; ……
propertyn : valuen ; }
ID Rules
Example :
---------------------------------------------
<html>
<head>
<title> Style Sheet with ID Rules </title>
<style>
#headingFormat
{ text-decoration : underline; font-family : Impact ;
color : pink ;
}
</style>
</head>
<body>
<h1 id=“headingFormat“ > CSS with ID Rules
</h1>
</body>
</html>
Class Rules
Syntax :
.Class Name { property1 : value1; ……
propertyn : valuen ; }
Class Rules
Example :
---------------------------------------------
<html>
<head>
<title> Style Sheet with ID Rules </title>
<style>
.headingFormat
{ text-decoration : underline; font-family : Impact ;
color : pink ;
}
</style>
</head>
<body>
<h1 class=“headingFormat“ > CSS with Class Rules
</h1>
</body>
</html>
---------------------------------------------
CSS Properties
CSS Measurement
○ in - inch
○ mm - millimeters
○ cm - centimeters
○ pt - point size
○ pc - picas
○ px - pixel
○ em - height – units
○ ex - x-height units
○ Percentage value i.e. 200%
- 72 pt = 1 inch
- 12 pt = 1 pica
- 6 pc = 1 inch
CSS Properties
CSS having more than 50 different
properties and values
Some properties might not work in
your browsers
CSS Properties
Font Properties
Text Properties
List Properties
Color and Background Properties
Box Properties
Margin Properties
Border Properties
Padding Properties
Height and Width properties
Display Properties
Font Properties
font-family
font-size
font-style
font-weight
font-variant
font
Font Properties
font-family
Used to set the font family (font name) for
the text
Possible Values
○ Arial, Serif, Cursive, etc..
Example
○ body { font-family : Arial, Futura,
Helvitica ; }
Font Properties
font-size
Used to set the relative or physical size of the font
used.
Possible Values
○ xx-small, x-small, small, medium, large, x-large, xx-
large
○ larger, smaller
○ 48pt, 2cm, 12px, or 0.25in
○ 150%
Example
○ p { font-size : 18pt ; }
Font Properties
font-style
Used to specify font style for the font being
used.
Possible Values
○ oblique ( simply slant the font.)
○ normal
○ italic
Example
○ h1 { font-style : italic ; }
Font Properties
font-weight
Selects the weight or darkness of the font.
Possible Values
○ 100 to 900
○ normal, bold, bolder, lighter
○ extra-light, light, demi-light, medium, demi-bold,
bold, extra-bold
Example
○ h1 { font-weight : 900 ; }
○ .important { font-weight : bolder ; }
Font Properties
font-variant
Used to select a variation of the specified
(or default) font family.
Possible Values
○ normal
○ small-caps
Example
○ h1 { font-variant : small-caps ; }
Font Properties
font
This property provides a concise way to specify
all the font properties with one style rule.
General form
○ font : font-style font-variant font-weight
font-size/line-weight font-family
Example
○ p { font : italic 12pt/24pt ; }
Example
○ body { vertical-align: bottom ; }
Text Properties
text-align
Determines how text in a block-level element,
such as <p> tag, is horizontally aligned.
Possible Values
○ left (Default)
○ right
○ center
○ justify
Example
○ div{ text-align: center ; }
Text Properties
line-height
Sets the height between lines in a block-
level element, such as a paragraph.
Possible Values
○ 10pt, 1cm, 2px, 0.25in etc…..
Example
p.double{ line-height: 2 ; }
Text Properties
white-space
Controls how spaces, tabs and newline
characters are handled in an element
Possible Values
○ normal
○ pre
○ nowrap
Example
○ p{ white-space: nowrap ; }
List Properties
list-style-type
list-style-image
list-style-position
list-style
List Properties
list-style-type
The items in ordered or unordered lists are
labeled with a numeric value or a bullet,
depending on the list form.
Possible Values
- For ordered list
decimal, lower-roman, upper-roman, lower-alpha, upper-alpha
none
Example
○ ul {list-style-image : url(flag.gif) ; }
○ ul {list-style-image : none; }
List Properties
list-style-position
Controls where a list item’s label is
displayed in relation to the element’s box.
Possible Values
○ inside
○ outside (Default)
Example
○ ul.compact {list-style-position : inside ; }
List Properties
list-style
This property allows a list’s type, image, or
position properties all to be set by a single
property.
This property can appear in any order and
are determined by value.
Example
○ ul.special {list-style : inside url(bullet.gif) ; }
Color and Background Properties
Three basic forms of color specifications :
Color names
e.g. Aqua, Black, Blue, Gray, Green, Lime, Pink etc..
Hexadecimal Values
e.g. #RRGGBB, #FF0088
RGB Values
e.g. RGB(0, 255, 0)
Color and Background Properties
color
background-color
background-image
background-repeat
background-attachment
background-position
background
Color and Background Properties
color
Used to set the text color.
Example
○ body { color : blue ; }
Color and Background Properties
background-color
Sets an element background color
Example
○ p { background-color : pink ; }
Color and Background Properties
background-image
Associates a background image with an
element
Example
○ body { background-image : URL(bars.gif) ; }
Color and Background Properties
background-repeat
Determines how background images file in
cases where they are smaller than the
canvas space used by their associated
elements.
Possible Values
○ repeat, repeat-x, repeat-y, no-repeat
Example
○ body { background-image : URL(bars.gif) ;
background-repeat : repeat-x ; }
Color and Background Properties
background-attachment
Determines whether a background image
should scroll or fixed on the screen.
Possible Values
○ scroll (Default)
○ fixed
Example
○ body { background-image : URL(bars.gif) ;
background-attachment : fixed ; }
Color and Background Properties
background-position
Specifies how a background image not a color, is
positioned within the canvas space used by its element.
Three Ways to do this :
○ Absolute distance
e.g. p { background-image : URL(picture.gif) ;
background-position : 10px 10px ; }
○ Percentage Value
e.g. p { background-image : URL(picture.gif) ;
background-position : 20% 40% ; }
○ With keywords
e.g. p { background-image : URL(picture.gif) ;
background-position : center center; }
Other possible values :
top left, top center, top right etc..
Color and Background Properties
background
This property is a comprehensive property
that allows any or all of the specific
background properties to be set at once.
Property order does not matter.
Any property not specified uses the default
value.
Example
○ p {background : white url(picture.gif) repeat-y top center
;}
Box Properties
Margin Properties
Border Properties
Padding Properties
Height, Width and Positioning
Properties
Margin Properties
Four margin properties are available to set
each of an element’s four margins
individually.
margin-top
margin-right
margin-bottom
margin-left
…..
<body>
<p id=“p1”>
Test paragraph 1 for width and height properties
</p>
<p id=“p2”>
Test paragraph 2 for width and height properties
</p>
…….
Display Properties
CSS contain several classification
properties that determine the display
classification of an element.
Allows an element’s display type to be
changed to one of four values.
Possible values
inline, block, list-item, none
Example
p { display : inline }
p .remove { display : none ;}