WT Notes PSP
WT Notes PSP
Introduction to HTML5
o Headings
o Linking
o Images
o Lists
o Tables
o Forms
Cascading Style Sheets (CSS)
o Types of CSS
o CSS Selectors
o CSS Positioning
o CSS Backgrounds
o CSS Box Model
o CSS Gradients
o Animation
JavaScript
o Introduction to JavaScript
o Control Statements
Introduction to HTML5
HTML stands for Hyper Text Markup Language.
Both tags will be similar except the (/) before the tag name
in ending tag.
Body section
Head Section
Tag Description
Example :
<html>
<head>
</head>
</html>
Body Section:
This section contains the tags, which make up the web page
very attractive.
Example:
<body bgcolor=”red”>
</body>
HTML Heading
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
HTML img tag is an empty tag that contains attributes only, closing tags
are not used in HTML image element.
1. src
2. alt
3. width
4. height
Example:
<!DOCTYPE>
<html>
<body>
<img src="Murugan.jpg" height="200" width="200" alt="God image">
</body>
</html>
Output
alt Attribute
The alt attribute defines an alternate text for the image, if it can't be
displayed. The value of the alt attribute describes the image in words.
HTML Linking
The HTML anchor tag defines a hyperlink that links one page to another
page.
It can create hyperlink to other web page as well as files, location, or any
URL.
The "href" attribute is the most important attribute of the HTML a tag.
and which links to destination page or URL.
The href attribute is used to define the address of the file to be linked.
void Elements
We can also link an image with other page or we can use an image as a
link. To do this, put <img> tag inside the <a> tag.
In the ordered HTML lists, all the list items are marked with
numbers by default. It is known as numbered list also.
The ordered list starts with <ol> tag and the list items start with
<li> tag.
Example:
<!DOCTYPE>
<html>
<body>
<ol>
<li>BAT</li>
<li>CAT</li>
<li>MAT</li>
<li>RAT</li>
</ol>
</body>
</html>
In HTML Unordered list, all the list items are marked with
bullets. It is also known as bulleted list also.
The Unordered list starts with <ul> tag and list items start with
the <li> tag.
<!DOCTYPE>
<html>
<body>
<ul>
<li>BAT</li>
<li>CAT</li>
<li>MAT</li>
<li>RAT</li>
</ul>
</body>
</html>
HTML Tables
HTML tables allow web developers to arrange data into rows
and columns.
Table Cells
Table Rows
Each table row starts with a <tr> and ends with a </tr> tag.
Table Headers
<html>
<body>
<table border=3 bordercolor=red align="center">
<tr>
<th bgcolor=yellow>text</th>
<th bgcolor=yellow>images</th>
</tr>
<tr>
<td> Murugan </td>
<td><img src="murugan.jpg" width=200 height=200></td>
</tr>
<tr>
<td> Saraswati </td>
<td><img src="saraswati.jpg" width=200 height=200></td>
</tr>
</table>
</body>
</html>
Output:
HTML Forms
An HTML form is used to collect user input. The user input is
most often sent to a server for processing.
<input> Element
<input type="radio"> Displays a radio button (for selecting one of many choices)
<input type="checkbox"> Displays a checkbox (for selecting zero or more of many choices)
<label> Element
Radio Buttons
Checkboxes
Submit Button
<!DOCTYPE html>
<html>
<head>
<title>Employee Details</title>
</head>
<body>
<form>
<fieldset>
<legend>Employee Details</legend>
<p>
First name: <input type = "text" name = "fname" />
</p>
<p>
Last name: <input type = "text" name = "lname" />
</p>
<p>
<input type = "radio" name = "Gender" value = "Male"> Male
<input type = "radio" name = "Gender" value = "Female"> Female
</p>
<p>
Employee ID: <input type = "text" name = "ID" />
</p>
<p>
Designation: <input type = "text" name = "ID" />
</p>
<p>
Phone Number: <input type = "text" name = "phone" />
</p>
<p>
<input type = "submit" name = "submit" value = "Submit" />
</p>
</fieldset>
</form>
</body>
</html>
Cascading Style Sheets (CSS)
CSS stands for Cascading Style Sheets.
Types of CSS
Example:
<html>
<body>
<h1 style=”color: red; font-style: italic”> RVR</h1>
</body>
</html>
Internal (embedded) style sheet:
Example:
<html>
<head>
<style>
h1 {color: red; font-style: italic}
p { color: green; font-style: bold}
</style>
</head>
<body>
<h1>RVR</h1>
<p>Rayapati Venkata Rangarao</p>
</body>
</html>
External style sheet:
Example:
mystyle.css
mypage.html
<html>
<head>
< /head>
<body>
<h1>RVR</h1>
</body>
</html>
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements
you want to style.
<!DOCTYPE html>
<html>
<head>
<style>
h1
{
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1>II/IV CSE A-SECTION Students </h1>
</body>
</html>
CSS id Selector
<!DOCTYPE html>
<html>
<head>
<style>
#a
{
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1 id=”a”>II/IV CSE A-SECTION Students </h1>
</body>
</html>
CSS class Selector
<!DOCTYPE html>
<html>
<head>
<style>
.a
{
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1 class=”a”>RVR&JC COLLEGE OF ENGINEERING </h1>
<p class=”a”> II/IV CSE A-SECTION Students</p>
</body>
</html>
CSS Universal Selector
<!DOCTYPE html>
<html>
<head>
<style>
text-align: center;
color: red;
</style>
</head>
<body>
<h2>CSE DEPARTMENT</h2>
</body>
</html>
CSS Grouping Selector
The grouping selector selects all the HTML elements with the
same style definitions.
Look at the following CSS code (the h1, h2, and p elements
have the same style definitions):
h1 {
text-align: center;
color: red;
}
h2 {
text-align: center;
color: red;
}
p{
text-align: center;
color: red;
}
It will be better to group the selectors, to minimize the code.
h1, h2, p {
text-align: center;
color: red;
}
CSS Positioning
CSS position is one of the key topics in CSS which helps to
understand how to place HTML elements at various locations
on a web page.
The CSS position property defines, as the name says, how the
element is positioned on the web page.
Relative Positioning:-
Absolute positioning:-
Example Description
h1,h3 {background-color:Yellow;}
Sets background color (Yellow) to elements (h1,h3).
CSS Box Model
HTML page is a collection of HTML elements (ex: P, DIV, H1).
Each element is considered as a box.
Output:
CSS Gradients
CSS gradients let you display smooth transitions between two
or more specified colors.
Linear Gradients
You can also set a starting point and a direction (or an angle)
along with the gradient effect.
Syntax
background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
Example:
<html>
<head>
<style>
#grad1
{
height: 200px;
background-color: red;
background-image: linear-gradient(red, yellow);
}
</style>
</head>
<body>
<h1>Linear Gradient - Top to Bottom</h1>
<p>This linear gradient starts red at the top, transitioning to
yellow at the bottom:</p>
<div id="grad1"></div>
</body>
</html>
Output:-
Radial Gradients
A radial gradient is defined by its center.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 150px;
width: 200px;
background-color: red;
background-image: radial-gradient(red, yellow, green);
}
</style>
</head>
<body>
<h1>Radial Gradient - Evenly Spaced Color Stops</h1>
<div id="grad1"></div>
</body>
</html>
Introduction to JavaScript
We can use JavaScript with HTML to create interactive web
pages.
Variables in JavaScript
<html>
<head>
<script>
var name;
name = 'Abhiram';
document.write(name);
</script>
</head>
</html>
UNIT II
JavaScript
o Functions
o Arrays
o JavaScript Objects
Functions in JavaScript
Functions are the basic building block of JavaScript. Functions
allow us to encapsulate a block of code and reuse it multiple
times.
Syntax:
Example:
<html>
<head>
<script>
function message()
{
document.write(“HELLO”);
}
</script>
<body>
<button onclick=”message()”>Message</button>
</body>
</html>
Random Number Generation
<html>
<head>
<script>
function RandomNumber()
{
document.getElementById('a').innerHTML= Math.random();
}
</script>
</head>
<body>
<button onclick=RandomNumber()>Random</button>
<h1 id="a"></h1>
</body>
<html>
Create a web page having radio buttons labeled as name of
colours. Clicking on each radio button should change the
colour of the Web page
<html>
<head>
<script>
function Pink( )
{
document.bgColor=”pink”;
}
function Red( )
{
document.bgColor=”red”;
}
</script>
</head>
<body>
<label><input type="radio" onClick=”Pink()”> Pink</label><br>
</body>
</html>
JavaScript Array
JavaScript array represents a collection of similar type of
elements.
Example:
<html>
<body>
<script>
var emp=["prasad","ramesh","chandra"];
for (i=0;i<emp.length;i++)
document.write(emp[i] + "<br/>");
</script>
</body>
</html>
Output:
Prasad
Ramesh
Chandra
Random Image Generator Using Arrays
<html>
<head>
<script>
function RandomImage()
{
var
i=["saraswati.jpg","lakshmidevi.jpg","murugan.jpg","saibaba.jpg"
];
var n=Math.floor(Math.random()*i.length);
document.getElementById('a').innerHTML=n;
document.getElementById('b').src=i[n];
}
</script>
</head>
<body>
<button onclick=RandomImage()>Random Image</button>
<h1 id="a"></h1>
<img id="b" width=200px height=200px>
</body>
</html>
Output:
JavaScript Objects
We know JavaScript is an object-based language.
Methods Description
min() It returns minimum value of the given numbers.
max() It returns maximum value of the given numbers.
pow() It returns value of base to the power of exponent.
round() It returns closest integer value of the given number.
sqrt() It returns the square root of the given number
round() It returns closest integer value of the given number.
random() It returns random number between 0 and 1
Write a Javascript code to find square root of the given number
<!DOCTYPE html>
<html>
<body>
<script>
document.writeln(Math.sqrt(12));
</script>
</body>
</html>
Output:
3.464
Write a Javascript code to generate random number
<!DOCTYPE html>
<html>
<body>
<script>
document.writeln(Math.random());
</script>
</body>
</html>
String Object
Example:
<!DOCTYPE html>
<html>
<body>
<script>
var str="SIVA PRASAD";
document.write(str);
</script>
</body>
</html>
Methods of String object
Methods Description
charAt() It provides the char value present at the
specified index.
concat() It provides a combination of two or more
strings.
indexOf() It provides the position of a char value present
in the given string.
substr() It returns closest integer value of the given
number.
toLowerCase() It converts the given string into lowercase
letter..
toUpperCase() It converts the given string into uppercase
letter.
Write a JavaScript code to find the length of a given string
<!DOCTYPE html>
<html>
<body>
<script>
var name="RVRJC";
document.write(name.length);
</script>
</body>
</html>
Output: 5
Date Object
The JavaScript Date object can be used to get year, month and
day. You can display a timer on the webpage by the help of
JavaScript date object.
Methods Description
It returns the integer value between 1 and 31 that
getDate()
represents the day for the specified date
<html>
<head>
<script>
var time=new Date();
var hrs=time.getHours();
var min=time.getMinutes();
var sec=time.getSeconds();
document.writeln("Time is "+hrs+":"+min+":"+sec+"<br>");
if((hrs>0)&&(hrs<=12))
document.writeln("good morning");
else if((hrs>12)&&(hrs<=16))
document.writeln("good afternoon");
else if((hrs>16)&&(hrs<=20))
document.writeln("good evening");
else
document.writeln("good night");
</script>
</head>
</html>
Number Object
Methods Description
parseInt() It converts the given string into an integer number.
parseFloat() It converts the given string into a floating point
number.
isInteger() It determines whether the given value is an
integer.
Boolean object
<script>
document.write(10<20);//true
document.write(10<5);//false
</script>