Introduction To Cascading Style Introduction To Cascading Style Sheets (CSS) Sheets (CSS)
Introduction To Cascading Style Introduction To Cascading Style Sheets (CSS) Sheets (CSS)
Introduction To Cascading Style Introduction To Cascading Style Sheets (CSS) Sheets (CSS)
Chapter 3
Learning Outcomes
In this chapter, you will learn to:
List advantages of using Cascading Style Sheets Create style sheets that configure common color and text properties Apply inline styles Use embedded style sheets Use external style sheets Create CSS class and id selectors Validate CSS
Before we start
http://www.csszengarden.com
CSS
provides the functionality of style sheets (and much more) for web developers a flexible, cross-platform, standards-based language developed by the W3C.
CSS Advantages
Greater typography and page layout control Style is separate from structure Styles can be stored in a separate document and linked to from the web page Potentially smaller documents Easier site maintenance
6
Inline Styles
Configured in the body of the Web page Use the style attribute of an XHTML tag Apply only to the specific element
2.
External Styles
Configured in a separate text file with .css file extension The XHTML <link /> element in the header section of a Web page associates it with the .css file
4.
Imported Styles
Similar to External Styles, uses the @import directive
@import url(file name);
Example: configure red color text in an <h1> element: <h1 style="color:#ff0000">Heading text is red</h1>
10
11
12
13
14
Checkpoint 1
16
17
font-style
Configures text to an italic style
font-size
Configures the size of the text
font-family
Configures the font typeface of the text
18
Accessibility Recommendation:
Use em or percentage font sizes these can be easily enlarged in all browsers by users
19
Not everyone has the same fonts installed in their computer Configure a list of fonts and include a generic family name
21
CSS Selectors
CSS style rules can be configured for an:
HTML element selector (simple selector) class selector id selector
22
bold; }
23
24
25
id Selector
Apply a CSS rule to ONE element on a Web page. Configure with #idname
<style type="text/css"> #new { color: #FF0000; font-size:2em; font-style: italic; } </style>
The sample creates an id called new with red, large, italic text. To use the id, code the following XHTML:
<p id=new>This is text is red, large, and in italics</p>
26
CSS PseudoPseudo-classes
Pseudo classes are styles that apply when something happens, rather than because the target element simply exists Names begin with colons hover classes apply when the mouse cursor is over the element focus classes apply when an element has focus
27
29
clients.htm
about.htm
Etc
30
31
To link to the external style sheet called color.css, the XHTML code placed in the header section is: <link rel="stylesheet" href="color.css" type="text/css" />
32
33
34
Summary
This chapter introduced you to Cascading Style Sheet Rules associated with color and text on web pages. You configured inline styles, embedded styles, and external styles. You applied CSS style rues to HTML, class, and id selectors. You are able to submit your CSS to the W3C CSS Validation test.
35