css - introduction

Demo page of applying CSS

Welcome to CSS Portion

In this introduction page of CSS you can learn following concepts:

1. CSS Definition

2. Features

3. CSS Rule

4. CSS Types

5. CSS Selectors

6. Id Selector

7. Class Selector


CSS Definition

CSS - Cascading Style Sheet

Features

CSS were added to HTML 4.0.
Its define how to display html elements.
CSS reduced the lot of editing work in HTML page.
CSS styles saved as separate stylesheet document with the extension of .css and applied to the HTML Document.

CSS Rule

Normally, CSS has two parts like one is Selector part and other one is Declaration part.
Example
h1 {color:red;}
In the above example 'h1' is selector and {color:red;} is declaration.

You can write multiple declaration for one selector.
Example
h1 {color:red; font-size:14px; background-color:#CCCCCC;}

You can write styles like below for more readable:
h1
{
color:red;
font-size:14px;
background-color:#CCCCCC;
}

You can give comments for your codes like below:
/* your comments */.
This is the comment rule for CSS.
Note: Comment section does not compiled when coding run.
h1 /* style for heading tag */
{
color:red; /* for red color */
font-size:14px; /* for text size */
background-color:#CCCCCC; /* for background color */
}

CSS Types

Three types of Stylesheets are there.

Internal Style Sheet
External Style Sheet
Inline Style Sheet

Internal Style Sheet

Internal Style sheets will be written within the HTML Document into the HTML head tag.

External Style Sheet

External Style sheets will be written as separated style sheet and saved with extension of .css and linked to the HTML Document.

Inline Style Sheet

Inline Styles will be written within the HTML Element.


CSS Selectors

Two type of Selector are there. These are very powerful sources of CSS. One is ID Selector and other one is Class Selector.

Id Selector

The Id Selector defines styles for single unique html element.
The Id Selector uses the id of html element and normally its defined by this "#" mark.

Example
Below style defines all the elements in the html document named with id of "#sample".
#sample {color:green; font-size:12px; background-color:#fff;}

Class Selector

The Class selector is used to indicate a style for group of elements.
The Class Selector may apply styles for many HTML elements in the document.
The Class Selector defined by this "." mark.

Example
Below style defines all the elements in the html document named with id of ".sample".
.sample {color:green; font-size:12px; background-color:#fff;}

Demo

Here you can view the sample demo which one applying style sheet.

Code view for demo

You can copy below code and paste into the Text Editor Program [like Notepad] and save as .html document and open that file in any browser window.



0 comments:

Template by Clairvo Yance
Copyright © 2013 EASYCODE and Blogger Themes.