CSS1
CSS1
CSS1
CSS Rules, Types, Font Properties, Text Formatting Properties, Border Properties, Margin
Properties, Color Properties, Link Properties, Position Properties, Padding Properties, List
Properties, span & div tags etc.
Learning with this CSS tutorial will give you a very confident start with its implementaion. So,
let's start!
Introduction
1) XSLT
eXtensible Style sheet Language Transformation.
It is applicable only for XML document.
2) CSS
Cascading Style Sheets.
It is applicable for HTML and XML or any web language.
HTML CSS
HTML stands for hyper text mark CSS stands for Cascading Style Sheet.
up language.
It specifies web page elements like CSS determines an element size, color etc.
table, paragraph etc.
It is used to identify the content of It is used to specify the presentation of that
the web page. content.
It is used for defining the web page CSS is used for styling and formatting the
structure. structured content of the web pages.
Advantages of CSS
Reusability: It means CSS file once created can be reused.
Easy maintenance: If any changes are required for any web page or document then changes can
be simply made in a CSS file where all elements in the web pages or document will be updated
automatically.
Download content faster: CSS requires less code and controls the order of element so that
content can be downloaded before images.
Platform Independent: The scripts are platform independent and support all the latest
browsers.
Limitations of CSS
CSS cannot create layout effect.
It does not give absolute control over a page's appearance.
It does not guarantee any kind of absolute pixel control
Types of Selectors
1. The Element / Tag selector
It is used to define tags associated with HTML.
Syntax:
TagSelector {Property : Value; }
Examples:
H1 {color : pink;}
H1, p {font-family : times roman;}
2. Class selectors
It is used to define styles without redefining plain HTML tags.
Syntax:
.ClassSelector {Property : Value;}
Output:
3. ID selectors
ID selector is used to define styles relating to objects with a unique ID.
Syntax:
#IDSelector {Property : value;}
4. Grouped Selectors
If there are elements with the same style definitions, then it is easy for the group selector to
minimize the code.
Group selectors are specified with comma (,) in between their names.
Syntax:
Selector1, selector 2, ….{property : value;}
Example: Illustration of grouped selector
<!DOCTYPE html>
<html>
<head>
<style>
h1, p {color : red;}
</style>
</head>
<body>
<h1> Welcome </h1>
<p> welcome Students </p>
</body>
</html>
Output:
Note: In the above program, same declaration is applied for both <h1> and <p> tags.
5. Context Selectors
Output:
6. CSS comments
Output:
Note: Comments work only in the CSS code whereas in HTML code they do not work.
Types of Style Sheets
If we want to apply the same style declaration to different elements every time.
Inline style sheet mixes the content with the presentation. So, if you want to avoid this mixing
up, don't use Inline style sheet.
Example: Demonstration of inline style sheet
<html>
<head>
<title> Inline CSS</title>
<meta http-equiv="content-style-type" content="text/css">
</head>
<body style="background:orange">
<h1 style="color:White; font-family:arial; font-size:14pt; text-transform:uppercase; text-
align:left;"> This is an example of inline css</h1>
</body>
</html>
Output:
2. Embedded or internal style sheet
The style specifications are defined within the head section of the web page or HTML page.
In this style sheet type, the alternate method of attaching a style sheet to HTML document is
<STYLE> tag.
While using <STYLE> tag it must include TYPE attribute.
TYPE attribute specifies what type of style is included in the document.
The attributes of <STYLE> element tag are:
1. type
Output:
Example 2: Demonstration of embedded style sheet
<!DOCTYPE html>
<html>
<head>
<title> Embedded CSS</title>
<style type="text/CSS">
body {
background-color:#ccffff;
}
h1 { color: purple; font-family: arial; font-size: 30 px; text-transform: uppercase; text-
align: left;}
</style>
</head>
<body>
<h1>Computer programming languages</h1>
<table border="1">
<tr>
<th>Web-tech</th>
<th>Object-Oriented</th>
</tr>
<tr>
<td>CSS</td>
<td>java</td>
</tr>
</table>
<p>Embedded CSS is better than Inline CSS</p>
</body>
</html>
Output:
3. External style sheet
In external style sheets, the CSS files are kept separately from an HTML document.
External CSS file contains only CSS code and it is saved with a “.css” extension.
The CSS file is used as an external style sheet file in HTML document by using a <LINK> tag
instead of <STYLE> tag.
The <LINK> tag is placed in the <HEAD> section of the HTML document.
The main advantage of External style sheet is that external CSS is a “true separation” of style
and content.
It is easier to reuse CSS code in any separate file.
Syntax:
<HEAD> <LINK REL=“stylesheet” TYPE=“text/css” HREF=“mystyle.css”>
</HEAD>
1. rel
It is used to specify a relationship of CSS with HTML document.
Its default relationship value is “style sheet”.
Possible relationship values are stylesheet/alternate stylesheet.
2. type
Type attribute is not used in META tag.
It specifies which type of style language is used.
The value of the type attribute is “text/CSS”.
3. href
It points to the external style sheet file's URL.
It specifies the path of the style sheet file which is linked with the HTML document.
4. title
It is optional.
It indicates the name of the style sheet.
Example: Demonstration of external style sheet
NOTE: Save following program as external.css
body { background:#ccffff;}
h2,p {
color: green;
font-family:arial;
text-align:center;
}
p i{
color: orange;
border-style: solid;
font-weight: lighter;
}
.ex{color:purple}
NOTE: Save following program as external.html and link above CSS file in it.
<html>
<head><title>Extenal style sheet</title>
<link rel= "stylesheet" type= "text/CSS" href="external.css">
</head>
<body>
<h2> It is an example of External style sheet</h2>
<p class="ex"> This is a "true separation" of style and content</p>
<p><i> External CSS </i> </p>
</body>
</html>
Output:
NOTE: To run the program, save the above .css and .html files on the same location or folder.