html
Version 0.6
19.12.2010
Revision History
Revision 0.1 12.04.2007 Lars Vogel
created
Revision 0.2 - 0.7 05.11.2009 - 19.12.2010 Lars Vogel
bugfixes and enhancements
This article explains how to use CSS for styling HTML pages.
Table of Contents
2. Usage of CSS
2.1. First example
In the same directory define this HTML file. This file defines that it will use the style sheet "styles.css" which can be found in
the same directory.
1 of 7 4/11/2011 4:00 PM
Cascading Style Sheets (CSS) - Tutorial http://www.vogella.de/articles/CSS/article.html
CSS defines via selectors certain values for pre-defined properties. This follows the following syntax,
For example the following css file defines the size an color for header tag h1. The rest of the HTML file is not affected by
this definition.
HTML elements can have and id and / or an class attribute. An id must be unique in the HTML document while the class
attribute can be defined for several HTML elements. CSS allows to style these elements via special selectors. HTML also
allows to define sections via "div" containers. These "div" containers can be used to style parts of the HTML document
differently. div can also be identified by an id and / or by a class and can container other block elements.
The following example demonstrate both usages. Create the file "stylesdiv.css"
2 of 7 4/11/2011 4:00 PM
Cascading Style Sheets (CSS) - Tutorial http://www.vogella.de/articles/CSS/article.html
You can also select by position in the HTML document. For example "td a" only selects links which are within a table row.
You can also use other attributes for example the following will define certain styling for links which have been visited or
over which the mouse hovers. The will identify if you have a link already visited or if the mouse hovers over a link and will
change the display of the link accordingly.
3. Defining size
The most consist way to define size is the unit "em" which is a relative unit to the font-size. 1em is as large as the font-size.
You can use 1em for defining the space between words (word-spacing), or letters (letter-spacing) or to define the line
height (line-height) of an HTML element. text-indent allows you to define the intent of the first line of a paragraph.
text-indent: -1em put the first line a bit before the rest of the text.
3 of 7 4/11/2011 4:00 PM
Cascading Style Sheets (CSS) - Tutorial http://www.vogella.de/articles/CSS/article.html
The total size of the HTML box is defined by the initial size of the box, plus the margins and the padding and a border, if
defined.
Frequently you want to make sure that you boxes stay on a specific place. You can use postion:absolute for this. A block
element with this style will be removed from the normal flow of the HTML page and will have a fixed space. For example:
If you want to have a element always on a certain position you can use the fixed position and will not move even if you scroll
down the HTML page.
4 of 7 4/11/2011 4:00 PM
Cascading Style Sheets (CSS) - Tutorial http://www.vogella.de/articles/CSS/article.html
5 of 7 4/11/2011 4:00 PM
Cascading Style Sheets (CSS) - Tutorial http://www.vogella.de/articles/CSS/article.html
8. Thank you
Please help me maintaining this article:
106
6 of 7 4/11/2011 4:00 PM
Cascading Style Sheets (CSS) - Tutorial http://www.vogella.de/articles/CSS/article.html
Free premium phpBB styles Community favorite phpBB styles by STSoftware design team stsoftware.biz
Create Website like Pro Easy for Novice, powerful for Pros Get 50% off (Promo code "dnjsgud" ) www.Namo.com
OSS Fast Infoset Tools Fast, compact XML without a schema Ideal for embedded devices. Evals. www.oss.com
7 of 7 4/11/2011 4:00 PM