Cascading Style Sheets: Presented by
Cascading Style Sheets: Presented by
Style Sheets
(CSS)
Presented by
Nguyễn Đức Thái
Ho Chi Minh City University of Technology
Outline
§ CSS Overview
§ CSS Rules
§ Example with Type Selectors and the
§ Universal Selector
§ CSS Syntax and Style
§ Class Selectors
§ ID Selectors
§ span and div Elements
§ CSS Properties
2
CSS Introduction
§ Focus on presentation of web page content.
§ Presentation refers to appearance and format.
§ CSS has concepts and basic syntax.
§ We can apply CSS rules to various elements.
§ CSS positions:
• Inline
• Internal
• External
4
CSS Overview (2)
§ Why is that separation strategy a good thing?
§ Because if you want to change the appearance of
something, it’s easy to find the CSS code.
6
CSS Rules - Illustration
7
CSS Rules - Illustration
8
CSS Syntax
§ Syntax for the style container.
<style>
* {text-align: center;}
hr {width: 50%;}
h2, p {font-style:
italic; color: blue;}
</style>
9
CSS Style
10
Class Selectors
11
ID Selectors
12
span and div Elements
span and div elements
13
CSS Rule Priority
14
Internal Style (CSS in Entire Web Page)
15
External Style (CSS in A Separated File)
16
CSS Properties
17
CSS Properties
18
Color Properties
§ The color property specifies the color of an element’s text.
§ The background-color property specifies the
background color of an element.
§ You can specify a color value using one of five
different formats:
• color name—for example, red
• RGB value—red, green, and blue
• RGBA value—red, green, and blue, + amount of opacity
• HSL value—hue, saturation, and lightness
• HSLA value—hue, saturation, and lightness, + amount of
opacity
19
Color Names
§ The CSS3 specification defines 147 color names, and
the major browsers support all those colors.
20
RGB Values for Color
§ RGB stands for red, green, and blue.
21
Opacity
§ Opacity determines how opaque the color is, where
opaque refers to the inability to see through
something.
§ It’s the opposite of transparency.
§ If the opacity value is 100%, that means the color is
completely opaque, and if there is content behind the
color, that content gets covered up.
§ At the other extreme, if the opacity value is 0%, that
means the color is completely transparent.
rgba(red-integer,green-integer,blue-integer,opacity-number-between-0-and-1)
rgba(red-percent,green-percent,blue-percent,opacity-number-between-0-and-1)
22
Using Colors - Example
23
Font Properties
§ font-style,
§ font-variant,
§ font-weight,
§ font-size,
§ font-family
24
font-style
25
font-variant
26
font-weight
27
font-size
28
Absolute Units
§ There are quite a few other techniques for specifying
font size.
29
font-family
30
font Shorthand
font: [font-style-value] [font-variant-value] [font-weight-value]
font-size-value [/line-height-value] font-family-value
31
line-height
32
Text Properties
§ text-align,
§ text-decoration,
§ text-transform,
§ text-indent.
33
text-align
34
text-decoration
35
text-transform
36
text-indent
§ The text-indent property specifies the size of the
indentation of the first line in a block of text.
§ The block’s second and third lines (and so on) are
unchanged; that is, they do not get indented.
§ If you want to adjust all the lines in a block of text, use
the margin property, not the text-indent property.
§ The most appropriate way to specify a value for the
text-indent property is to use em units.
p {text-indent: 4em;}
37
Border Properties
§ border-style,
§ border-width,
§ border-color.
38
border-style
39
border-width
.box {
border-style: solid;
border-width: 4px 2px 0px 2px;
}
40
Border Shorthand
.box {
border: thin solid blue;
}
.box2 {
border: 10px dotted;
}
41
Element Box
§ padding properties,
§ margin properties
42
margin & padding
43
margin & padding
§ The padding property specifies the width of the
area on the interior of an element’s border, whereas
the margin property specifies the width of the area
on the exterior of an element’s border.
§ Usually, the most appropriate type of value for the
padding and margin properties is a CSS pixel value.
§ Here’s an example CSS rule that uses padding and
margin properties:
44
margin & padding
45
Percentage for a Web Page’s Margin
§ Use CSS pixel values for margin widths.
§ Sometime appropriate to use percentage values
instead of pixel values.
§ Case in point—specifying the margin around the
entire web page.
body {margin: 10%;}
48