CSS - Introduction
CSS - Introduction
CH 4
LEARNING OUTCOMES
2
OVERVIEW OF
CASCADING STYLE SHEETS (CSS)
Style Sheets
used for years in Desktop Publishing
apply typographical styles and spacing to printed media
CSS
provides the functionality of style sheets
(and much more) for web developers
a flexible, cross-platform,
3 standards-based language
developed by the W3C.
CSS ADVANTAGES
4
CSS SYNTAX
Style sheets are composed of "Rules" that describe the styling to be applied.
5
CSS SELECTORS
This could also be written using hexadecimal color values as shown below.
7
CSS SYNTAX FOR COLOR VALUES
Inline CSS
Configured in the body of the Web page
Use the style attribute of an HTML tag
Apply only to the specific element
Examples
Inline Styles
Embedded Styles
External Styles
Imported Styles
10
DESCRIPTION OF THE TYPES OF
CASCADING STYLE SHEETS
Inline Styles
◦ Configured in the body of the web page
◦ Use the style attribute of an HTML tag
◦ Apply only to the specific element
Embedded Styles
◦ Configured in the head section of a web page.
◦ Use the HTML <style> element
◦ Apply to the entire web page document
External Styles
◦ Configured in a separate text file with .css file extension
◦ The HTML <link> element in the head section of a web page
associates it with the .css file
Imported Styles
11 ◦ Similar to External Styles
◦ We’ll concentrate on the other three types of styles.
THE “CASCADE”
12
CONFIGURE EMBEDDED CSS
WITH THE STYLE ELEMENT
13
STYLES CAN FIGHT- WHO WILL WIN?
15
EXTERNAL STYLE SHEETS - 2
body { background-color:
#E6E6FA;
about.html
color: #000000;
}
h2 { color: #003366; }
etc…
16
THE <LINK> ELEMENT FOR EXTERNAL STYLE SHEETS
A self-contained tag
Placed in the header section
Purpose: associates the external style sheet file
with the web page.
Example:
19
USING A CSS DESCENDANT SELECTOR
Descendant Selector
Apply a CSS
rule within the context of <style>
the container (parent) element.
footer p {color: #00ff00; }
Sometimes called a </style>
contextual selector.
An inline-level element
Purpose:
Configure a specially formatted area
displayed in-line with other elements,
such as within a paragraph.
There is no line break before
and after the span.
21
<SPAN> EXAMPLE
Embedded CSS:
<style>
.companyname { font-weight: bold;
font-family: Georgia, "Times New Roman", serif;
font-size: 1.25em; }
</style>
HTML:
<p>Your needs are important to us at <span class=“companyname">Acme
Web Design</span>. We will work with you to build your website.</p>
22
W3C CSS VALIDATION
http://jigsaw.w3.org/css-validator