Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS)
What is CSS?
Cascading Style
Sheets (CSS): is a
simple mechanism for
adding style (e.g. fonts,
colors, layouts) to Web
documents.
Styles provide powerful
control over the
presentation of web
pages
selector
property
value
rule
CSS Syntax
selector {property: value;}
Local
confined to a single element (tag)
Internal
affect elements in an entire page
External
can affect multiple pages
Precedence
Local > Internal > External
Example
Practice
1. add text-align property to make it centered
2. add border property to let it has black, 1px
thick, solid border at left, right, top, and bottom
How to create?
Put <style> </style> tag between
<head> and </head> tags of your HTML
page
Use type attribute to indicate the style
sheet type, usually type=text/css
Specify a default style sheet language for
the whole document by
<meta http-equiv="Content-Style-Type"
content="text/css" />
Put your set of style sheet rules in
between <style> and </style> tags
Practice
Create same style in the example in the
local style sheet section, but using
internal style sheet instead.
An external style sheet is simply a textonly file that contains only CSS rules.
How to link to external style sheet?
<link href=URL of CSS File"
rel="stylesheet" type="text/css" />
Practice
Create a file called mystyle.css and do
the example in local style sheet, but as
external style sheet