This is a paragraph.
, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process.
To solve this problem, the World Wide Web Consortium (W3C) created CSS.
In HTML 4.0, all formatting could be removed from the HTML document, and stored in a separate CSS file.
All browsers support CSS today.How to use CSS : How to use CSS CSS can be used in three ways:
inline.
Internal
external
Mostly internal and external CSS are used in most cases.
In-line : In-line In-line styles are fed straight ( at the spot) into the HTML tags using the style attribute.
They look something like this:
text
This will make that specific paragraph red.
But, if you remember, the best-practice approach is that the HTML should be a stand-alone, presentation free document, and so in-line styles should be avoided wherever possible.Internal : Internal Embedded, or internal styles are used for the whole page. Inside the head tags, the style tags surround all of the styles for the page.
This would look something like this:
CSS Example
...
This will make all of the paragraphs in the page red and all of the links blue.
Similarly to the in-line styles, we can keep the HTML and the CSS files separateExternal : External External styles are used for the whole, multiple-page website. There is a separate CSS file, which will simply look something like:
p {
color: red;
}
a {
color: blue;
}
If this file is saved as "web.css" then it can be linked to in the HTML like this:
CSS Example
...CSS Syntax : CSS Syntax Now whatever it usage may be, once you know its basic syntax then you can use it any way easily.
A CSS rule has two main parts: a selector, and one or more declarations:
The selector is normally the HTML element you want to style.
Each declaration consists of a property and a value.
The property is the style attribute you want to change. Each property has a value.
CSS Syntax : CSS Syntax
The id and class Selectors : The id and class Selectors In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called "id" and "class".
The id Selector
The id selector is used to specify a style for a single, unique element.
The id selector uses the id attribute of the HTML element, and is defined with a "#".
The style rule below will be applied to the element with id="para1":
Example
#para1{text-align:center;color:red;}
The class Selector : The class Selector The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements.
This allows you to set a particular style for many HTML elements with the same class.
The class selector uses the HTML class attribute, and is defined with a "."
In the example below, all HTML elements with class="center" will be center-aligned:
Example
.center {text-align:center;}
You can also specify that only specific HTML elements should be affected by a class.
In the example below, all p elements with class="center" will be center-aligned:
Example
p.center {text-align:center;}
Multiple Style Sheets : Multiple Style Sheets If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet.
For example, an external style sheet has these properties for the h3 selector:
h3{color:red;text-align:left;font-size:8pt;}
And an internal style sheet has these properties for the h3 selector:
h3{text-align:right;font-size:20pt;}
If the page with the internal style sheet also links to the external style sheet the properties for h3 will be:
color:red;text-align:right;font-size:20pt;
The color is inherited from the external style sheet and the text-alignment and the font-size is replaced by the internal style sheet.
Cascading order : Cascading order What style will be used when there is more than one style specified for an HTML element?
Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority:
Browser default
External style sheet
Internal style sheet (in the head section)
Inline style (inside an HTML element)
So, an inline style (inside an HTML element) has the highest priority, which means that it will override a style defined inside the
tag, or in an external style sheet, or in a browser (a default value).Example: CSS Background : Example: CSS Background CSS background properties are used to define the background effects of an element.
CSS properties used for background effects:
background-color
background-image
background-repeat
background-position
Background Color
The background-color property specifies the background color of an element.
The background color of a page is defined in the body selector:
Example
body {background-color:#b0c4de;}
background-image:url('paper.gif');
background-repeat:repeat-x;
background-position:right top;}