web unit2
web unit2
web unit2
HTML is used to build a static document DHTML describes the technologies used to
page and to specify the hyperlinks. build dynamic and interactive web pages.
HTML does not include server-side code. DHTML includes server-side code.
HTML is a simple static page with no DHTML is a dynamic page with HTML,
JavaScript or styles. CSS, DOM and JavaScript.
HTML files have the.htm or.html extension. DHTML files have the .dhtml extension.
HTML does not require database DHTML may require database connectivity
connectivity. as it interacts with the user.
HTML pages do not use event methods. DHTML pages make use of event methods.
CSS Syntax
In this example all <p> elements will be center-aligned, with a red text color:
p{
color: red;
text-align: center;
}
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue, and the text
color of the <p> element to red:
Example:
<h1 style="color:blue;">A Blue Heading</h1>
Internal CSS
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page, within
a <style> element.
The following example sets the text color of ALL the <h1> elements (on that page) to blue,
and the text color of ALL the <p> elements to red. In addition, the page will be displayed
with a "powderblue" background color:
Example:
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
External CSS
An external style sheet is used to define the style for many HTML pages.
Here styles will be saved in a separate file with an extension of .css and this .css file
will be linked in the head section of our desired file using <link> tag.
i.e To use an external style sheet, add a link to it in the <head> section of each HTML
page
Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The element selector selects HTML elements based on the element name.
Example
Here, all <p> elements on the page will be center-aligned, with a red text color:
p{
text-align: center;
color: red;
}
CSS Class Selector
The class selector selects HTML elements with a specific class attribute. It is used with a
period character . (full stop symbol) followed by the class name.
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1 class="center">This heading is blue and center-aligned.</h1>
<p class="center">This paragraph is blue and center-aligned.</p>
</body>
</html>
The grouping selector is used to select all the elements with the same style definitions.
Grouping selector is used to minimize the code. Commas are used to separate each selector
in grouping.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1, h2, p {
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello RDC</h1>
<h2>Hello RDC</h2>
<p>This is a paragraph.</p>
</body>
</html>
A contextual selector gives the combination of tags and sub-tags separated by space.
Example
<!DOCTYPE html>
<html>
<head>
<style>
B I{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<B><I>Hello RDC</I></B>
<I><B>Hello RDC</B></I>
<B>This is a bold text.</B>
<I>this is text in italic.</I>
</body>
</html>
A sub-class selector can have different classes,thus allowing the same element to have
different styles.
Example
<!DOCTYPE html>
<html>
<head>
<style>
H1.style1
{
text-align: center;
color: blue;
}
H1.style2
{
text-align: left;
color: red;
}
</style>
</head>
<body>
<h1 class=”style1”>Hello RDC1</h1>
<h1 class=”style2”>Hello RDC2</B></I>
</body>
</html>
CSS ID Selector
The id selector uses the id attribute of an HTML element to select a specific element.
The id of an element is unique within a page, so the id selector is used to select one unique
element!
To select an element with a specific id, write a hash (#) character, followed by the id of the
element.
Example
<!DOCTYPE html>
<html>
<head>
<style>
#para1
{
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1 id=”para1”>Hello RDC1</h1>
</body>
</html>
6. Write about position property in CSS?
A. The CSS position property is used to position different text or image at a
fixed position on the web page.
The property position may take any one of the following values:
Static
Absolute
Relative
Fixed
Ex: <HTML>
<HEAD>
<TITLE>POSITION</TITLE>
</HEAD>
<BODY>
<IMG SRC=”TULIPS.JPG”height=100 width=100
style=”position:absolute,left:0;top:0”>
</BODY>
</HTML>
Filters can be applied to HTML control elements through the CSS filter property.
style=”filter:filtername(parameters)”
For embedded and external styles the syntax for filter property is
Selector(filter:filtername(parameters))
Different visual filters are :
<html>
<head>
<title>
Filters
</title>
</head>
<body>
<table border=1>
<tr>
<td> normal</td>
<td>flip horizontal</td>
<td>flip vertical</td>
<td>flip horizontal and vertical</td>
</tr>
<tr style=”font-size=30”>
<td> RDC</td>
<td style=filter:”fliph”> RDC </td>
<td style=filter:”flipv”> RDC </td>
<td style=filter:”fliph flipv”> RDC </td>
</tr>
</table>
</body>
</html>
Example using filters on image
<html>
<head>
<title>
Filters
</title>
</head>
<body>
<table border=1>
<tr>
<td> invert</td>
<td>grayscale</td>
<td> xray</td>
<td>wave</td>
</tr>
<tr>
<td style=”filter:gray”><img src=”tulips.jpg”></td>
<td style=”filter:invert”><img src=”tulips.jpg”></td>
<td style=”filter:xray”><img src=”tulips.jpg”></td>
<td style=”filter:wave(strength=5)”><img src=”tulips.jpg”></td>
</td>
<tr>
<td> mask</td>
<td>alpha</td>
<td> blur</td>
<td>chroma</td>
</tr>
<tr>
<td style=”filter:mask(color=red”><img src=”tulips.jpg”></td>
<td style=”filter:alpha(opacity=50)”><img src=”tulips.jpg”></td>
<td style=”filter:blur(strength=20)”><img src=”tulips.jpg”></td>
<td style=”filter:chroma(color=blue)”><img src=”tulips.jpg”></td>
</td>
</table>
</body>
</html>
Important Questions
1. Define CSS?
2. Syntax of CSS?
Prepared by
P. MENAKA RAO
M.TECH, M.C.A, M.B.A, MA(ENGLISH)