CSS Summary
CSS (Cascading style sheets) are used to separate content from presentation. CSS describe the presentation of a document written most of the times in HTML. CSS is used to define colors, fonts and layout.
A style sheet file consists of a list of rules.
Each rule consists of:
- -one or more comma-separated selectors
- -declaration block (a list of semicolon-separated declarations in curly braces)
In CSS, selectors are used to declare which elements a style applies to, a kind of match expression. Here are some examples of selector syntax:
- All elements: that is, using the * selector
- By element name: e.g. for all p or h2 elements
- Descendants: e.g. for a elements that are descendants of li elements (e.g links inside lists) the selector is li a
- class or id attributes: e.g. .class and/or #id for elements with class="class" or id="id"
- Adjacent elements: e.g. for all p elements preceded by h2 elements, the selector would be h2 + p
- Direct child element: e.g. for all span elements inside p, but no span elements deeper within the hierarchy, the selector would be p > span
- By attribute:e.g. for all <input type="text"> the selector would be input[type="text"]
Each declaration consists of a property, a colon : and a value.
Example:
p {
font-family: "Garamond", serif;
}
h2 {
font-size: 110%;
color: red;
background: white;
}
To use a CSS style sheet created a file with the sytle sheet file with the rules and link it or import it using:
<link rel="stylesheet" href="example.css" type="text/css" >
<style type="text/css"> @import "example.css"</style>
For more information on CSS follow the link http://en.wikipedia.org/wiki/Cascading_Style_Sheets
0 Comments:
Post a Comment
<< Home