Basics
Creating a Document
Head and Body Elements
Formatting Text
Creating Lists
Embedding Images
URLs Explained
Linking to Documents
Creating Tables
Forms Form Basics
Input and Textarea
Select Lists
Frames Framesets
The Frame Element
Nested Framesets
Targetting Frames
Inline Frames
Tips and Tricks Meta Tags
Transition Effects
HTML Generators Create a Document
Create a List
Create a Table
HTML
Basics
Implementing CSS
CSS Syntax
Pseudo Classes/Elements
CSS Classes
CSS Properties Font Properties
Color and Background
Text Properties
Border Properties
Margins and Padding
Size and Position
Tips and Tricks Menu Buttons
Special Effects
CSS
Basics
Running a Script
Variables
Expressions and Operators
Objects.Properties.Methods
The Date Object
Strings
Regular Expressions
Defining RegExp Patterns
Branches and Conditions
Loops
Arrays Array Basics
Array Methods
Sorting Arrays

User-Defined Functions
Cookies
Windows
Frames
Tips and Tricks Image Replacement
Using Includes
Form Validation
Debugging
JavaScript
Basics
Creating a Script
Running a Script
Variables
Expressions and Operators
Strings Strings Basics
Strings and Substrings
Replacing Substrings
Regular Expressions
Branches and Conditions
Loops
Arrays Array Basics
Array Functions
Sorting Arrays
User-Defined Functions
Include and Require
Uploading Files
File Functions
Session Variables
Tips and Tricks Page Templates
Form Reply Scripts
Form Validation
JavaScript to PHP
PHP
Basics
Create and Drop
Show and Describe
Insert, Update and Delete
Querying
Join Queries
Functions
Table Locking
PHP/MySQL Functions Accessing a Database
Querying with PHP
Create and Drop with PHP
Insert and Update with PHP
Frequently Used Functions MySQL
Basics
Layout and Navigation
Page Content Style
Web Page Copy
Graphics and Animation
HTML Forms
Accessibility
Legal Requirements
MySQL
CSSBasicsImplementing CSSImplementing CSSCSS SyntaxPseudo Classes/ElementsCSS ClassesCSS PropertiesFontColor and BackgroundTextBorderMargins and PaddingSize and Position

Home > CSS > Implementing CSSprinter version

Implementing CSS

CSS can be implemented in three ways that have slightly different effects.

  1. Inline - This is where a style definition is applied directly to a single HTML tag as an attribute.
  2. Using the <style> element - This is where a style declaration is placed within the head of a document.
  3. Using the <link> element - This is where the style declaration is placed within an external style document and is linked to from an HTML document.


Using the Inline Style Attribute

This way of setting style is easy to use but requires that each tag be specified individually using a style attribute. This removes the advantage of being able to set style universally across multiple documents leaving you little better off than if you had used <font>.

More than one style property may be specified within the attribute as shown below with a paragraph element.

Inline Style Example
<p style="color: #ff0000; font-size: 15px;">This paragraph is red</p>


Using the <style> Element

This is a style declaration within the head of a document using the <style> element.

This means that any change to the style declaration will only affect this page and similarly removes the advantage of being able to set style universally across multiple documents - however maintenance is easier than with inline style.

<style> Element Example
<html>
<head>
<style type="text/css">
  p {
    color: #ff0000;
    font-size: 15px;
  }
</style>
</head>
<body>
    <p>This paragraph is red</p>
</body>
</html>


Using the <link> Element

This uses a link within the head section of an HTML document to an external style document. Since the link can be placed on multiple pages then a change to the style document will affect all pages that contain the link.

<link> Element Example
<html>
<head>
    <link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
    <p>This paragraph is red</p>
</body>
</html>


Example Style Sheet "mystyle.css" Linked to by the Above
p {
    color: #ff0000;
    font-size: 15px;
}


The style sheet "mystyle.css" is a plain text file saved with a .css extension instead of .txt and only contains the information that would be placed between the opening and closing <style> tags.

What Cascading Means

This can be quite a complicated issue since multiple style declarations can be made that apply to the same elements - and this causes conflicts.

But assuming that you don't implement multiple external linked style sheets then it can be simplified to that below.

  1. If there are no style declarations then the browser implements its default style.
  2. If there is a style definition then this overrides the browser and becomes the default.
  3. If there is an external linked stylesheet and a <style> element within the head of a document and a conflict occurs then the <style> element becomes the default.
  4. If there is an external linked stylesheet, a <style> element within the head of a document and an inline style declaration and a conflict occurs then the inline style declaration becomes the default.


To summarise: Inline has priority over the <style> element which has priority over the external linked stylesheet which has priority over the browser.

Previous - CSS Basics Previous - CSS Basics     Next - CSS Syntax Next - CSS Syntax


Privacy | Terms | Contact | Links | Sitemap | RSS Feeds RSS and JavaScript Feeds
©2010 www.webdesignworkmate.co.uk all rights reserved 
Design and Production by smallbizonline website design © 2000-2010
Valid HTML 4.01! Level Double-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0Valid CSS!
Tips and TricksMenu ButtonsSpecial Effects
Got any CSS Tips?
Send me your tip and if it's suitable I'll put it on the site, credit it to you and add a link back to your site.
Recommended Reading
CSS - the missing manual

The CSS anthology

Beginning CSS web development