14-11-2012, 01:58 PM
Cascading Style Sheets
css.doc.pdf (Size: 219.29 KB / Downloads: 31)
What is CSS?
● CSS stands for Cascading Style Sheets
● Styles define how to display HTML elements
● Styles were added to HTML 4.0 to solve a problem
● External Style Sheets can save a lot of work
● External Style Sheets are stored in CSS files
Styles Solved a Big Problem
HTML was never intended to contain tags for formatting a document.
HTML was intended to define the content of a document, like:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
When tags like <font>, and color attributes were added to the HTML 3.2 specification, it
started a nightmare for web developers. Development of large web sites, where fonts and
color information were added to every single page, became a long and expensive process.
To solve this problem, the World Wide Web Consortium (W3C) created CSS
The class Selector
The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most
often used on several elements.
This allows you to set a particular style for any HTML elements with the same class.
The class selector uses the HTML class attribute, and is defined with a "."
In the example below, all HTML elements with class="center" will be center-aligned:
Multiple Styles Will Cascade into One
Styles can be specified:
● inside an HTML element
● inside the head section of an HTML page
● in an external CSS file
Tip: Even multiple external style sheets can be referenced inside a single HTML document.
Cascading order
What style will be used when there is more than one style specified for an HTML element?
Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules,
where number four has the highest priority:
1. Browser default
2. External style sheet
3. Internal style sheet (in the head section)
4. Inline style (inside an HTML element)
So, an inline style (inside an HTML element) has the highest priority, which means that it will override a style defined
inside the <head> tag, or in an external style sheet, or in a browser (a default value).
Note: If the link to the external style sheet is placed after the internal style sheet in HTML <head>, the external style
sheet will override the internal style sheet