Вы находитесь на странице: 1из 4

Practical no.

2
Introduction of CSS

CSS:-CSS stands for Cascading Style Sheets. Styles define how to display HTML
elements. Styles are normally stored in Style Sheets Styles were added to HTML 4.0 to
solve a problem (contents of HTML documents was clearly Separated from the
documents presentation layout).External Style Sheets can save you a lot of work.
External Style Sheets are stored in CSS files. Multiple style definitions will cascade into
one .CSS saves a lot of work. It can control the layout of multiple web pages all at once.

CSS Syntax:-The CSS syntax is made up of three parts: a selector, a property and a
value:

Selector {property: value}

The selector is normally the HTML element/tag you wish to define, the property is the
attribute you wish to change, and each property can take a value. The property and value
are separated by colon, and surrounded by curly brace:

Body {colour: black}

Ways to Insert CSS

There are three ways to inserting a style sheet:-

External Style Sheet


Internal Style Sheet
Inline Style Sheet

External Style Sheet: - An external style sheet is ideal when the style is applied to many
pages. With an external style sheet you can change the look of an entire web page by
changing one file. Each page must link to the style sheet using the <link> tag.

p{

margin-left:10px;

margin-right:20px;

padding:10px;

background-color"#ffcc99;

border:5px dotted gray;


}

<html>

<head>

</head>

<link rel="stylesheet"type="text/css" href="style.css" />

<body>

<p>he is widely regarded as one of the greatest finishers in limited-overs


cricket. <br>

He made his One Day International (ODI) debut in December 2004 against
Bangladesh

</p>

</body>

</html>

Internal Style Sheet:- An internal style sheet should be used when a single document
has a unique style. Internal style can be defined in the head section of an HTML page
by using the <style> tag.

<html>
<head>
<style>
.a2
{
text-align: enter;
text-shadow: 1px 1px #000;
text-decoration: underline;
}
</style>
</head>
<body >
<table border="2" width="200px" height="250px">
Page 7
<tr><td>
<h1 class="a2">Welcome</h1>
<p class="a2"> You are very nice</p>
<h2 class="a2">God Bless You</h2>
</td>
</table>
</body>
</html>

Inline Style Sheet: - An inline style may be used to apply a unique style for a single
element. To use inline styles, add the style attribute to the relevant element. The style
attribute can contain any CSS property.

<html>
<head>
</head>
<body>
<table border="2" width="250px" height="150px">
<tr>
<td>
<h1 style="background-color:orange";
<h1><i>JAI HIND</h1>
<h2 style="background-color:green";
<h2><em>I LOVE MY INDIA </h1>
<h3 style="background-color:orange";
<h3><i>GOD BLESS TO MY INDIA</h1>
<h4 style="background-color:green";
<h4><em>God Bless You to all </h1></td></tr>
</table>
</body>
</html>

Page 8
Advantages of CSS

Easier to maintain and update.


Greater consistency in design.
More formatting options.
Lightweight code.
Faster download times.
Search engine optimization benefits.

Page 9

Вам также может понравиться