| Cascading Style Sheets (CSS) Tutorial. Inline, embedded and external styles. |
![]()
|
Page Contents.
IntroductionThis page introduced 31 Jul 03 is being worked on. More information will be added Style Sheets, Cascading Style Sheets and CSS are all mean the same thing and are the modern way of defining the design and layout of your web page(s). An ideal way of replacing the deprecated tags and attributes, such as the FONT tag. In this tutorial you will learn how to change the look of your pages, background, text and link colours, the look of tables, headings borders and many other aspects of a pages appearance, using CSS. With CSS you can either |
|
|
Defining a StyleA style is defined with three sections: a selector, a property and a value as follows selector {property: value} Example of defining a HTML tag: P {font-size: 10pt}
Where several properties and values are required for a particular selector, the above can be repeated P {font-size: 10pt} or the following shortcut can be used selector {property: value; property: value; property: value; } Example:
BODY {
Applying Style SheetsThere are 3 types of style sheets. The difference is where the style is defined and the area where that style is applied.
Note that more than one of these 3 types can be used on a page, and you can link more than one External style sheet to a page. 1. Inline style sheet Within a tagUse forInline style sheet are should only be used where a particular style is not going to be repeated elsewhere on the page/site. Where to defineThe definition is defined within the HTML tag in the body section of the HTML code. It must be redefined every time it is required SyntaxThe sytax for inline styles is slightly simpler than that of Internal and External styles in that there is no selector and no curly brackets.
Using style example 2. Internal style sheetWhere to defineThe definition is written once in In the head part of a page. It must be written on every page that requires that style. Use forBecause of the above it is ideal if only 1 page is going to be used for this style. The styles can then be used more than once throughout the page. The Internal style sheet is defined within the head section. <head> Example: <head> 3. Create a separate style sheet fileUse forThis is the best method if you wish to control the design of more that one page. Where to defineThe style definitions are only written once and saved into a file. Each page that wishes to use that file places a link to the file in the HEAD section. <HEAD> Section of your pages Place the following link into the <head> section of your page, use the name you have selected for the CSS file in place of yourStyleFileName.css <link rel="STYLESHEET" href="yourStyleFileName.css" type="text/css"> CSS external fileCSS files are ordinary text files and can be written in a simple text editor such as notepad. The file must be given the extension .css CascadingThe term Cascading is used because more than 1 style sheet can be used on any particular page. Order of precedenceIf the same style is defined with different values in the different style sheets then the order of precedence is Inline Style Sheets Internal Style Sheets The last External Style sheet moving in order to the first
External Style Sheet linked in the head section, BODY tagThe Body tag has properties and values that control the appearance of the page. The following code example code has the more popular properties and values BODY { font-family:As stated earlier the font that is selected by you can not be used unless that font is on the users computer. Therefore only popular fonts should be used. As a safeguard more that 1 font can be defined. This allows alternative fonts to be stated, in case your first choice is unavailable on the users computer. It is better to list more than 1 font to ensure that the user views your page as intended. The selection should end with a generic font e.g. serif, sans-serif, cursive, fantasy, or monospace. Fonts with spaces in there names such as "Times New Roman" must be placed in quotes.
|
|
|
font-sizeThe size of the font can be in
Examples: font-size: 10px; font-size: 8pt;
|
| Dreamweaver |
has a built is CSS editor that writes all the code for you. Students can obtain Dreamweaver in the Macromedia Student Studio
MX |
| |
|
|
|
|
Leisure Time - book your holiday or flights with our UK sponsorsMore Tutorials by John McGuinn
Leeds my home town Relax in the sun.
Copyright © John McGuinn 2001-03 . |