Unit 3 - Internet and Web Technology - WWW - Rgpvnotes.in
Unit 3 - Internet and Web Technology - WWW - Rgpvnotes.in
Tech
Subject Name: Internet and Web Technology
Subject Code: CS-504
Semester: 5th
Downloaded from www.rgpvnotes.in
Subject Notes
A Style Sheet is a collection of style rules that that tells a browser how the various styles are
to be applied to the HTML tags to present the document. Rules can be applied to all the
basic HTML elements, for example the <p> tag, or you can define you own variation and
apply them where you wish to.
There are three types of Style Sheets:
Embedded: the style rules are included within the HTML at the top of the Web page -
in the head.
Inline: the style rules appear throughout the HTML of the Web page - i.e. in the
body.
Linked: The style rules are stored in a separate file external to all the Web pages.
INTRODUCTION TO CSS
HTML was NEVER intended to contain tags for formatting a web page!
HTML was created to describe the content of a web page, like:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
When tags like <font>, and color attributes were added to the HTML 3.2 specification, it
started a nightmare for web developers. Development of large websites, where fonts
and color information were added to every single page, became a long and expensive
process.
The declaration block contains one or more declarations separated by semicolons. Each
declaration includes a CSS property name and a value, separated by a colon. A CSS
declaration always ends with a semicolon, and declaration blocks are surrounded by curly
braces.
Example:
In this example all <p> elements will be center-aligned, with a red text color:
p{
color: red;
text-align: center;
}
You can set background images in CSS using the background-image and several other
properties to control the behaviour of the image. Background properties
include: background-repeat. Background-attachment.
Top.
Right.
Bottom.
Left. Enter.
any combination of the above
CSS background-image Property
Adding color is done using the "color" property for the foreground color and the
"background-color" property for the background color. The "color" property specifies the
color of the text for the HTML element. There are 2 ways to specifycolor in CSS:
h1 {
color: #00ff00;
}
p.ex {
color: rgb(0,0,255);
}
This text is styled with some of the text formatting properties. The heading uses the text-
align, text-transform, and color properties. The paragraph is indented, aligned, and the
space between characters is specified.
Text Color
The color property is used to set the color of the text. The color is specified by:
Look at CSS Color Values for a complete list of possible color values.
Example :
body {
color: blue;
}
h1 {
color: green;
}
CSS Fonts is a module of CSS that defines font-related properties and how font resources
are loaded. It lets you define the style of a font, such as its family, size and weight, line
height, and the glyph variants to use when multiple are available for a single character.
Font Family
The font-family property should hold several font names as a "fallback" system. If the
browser does not support the first font, it tries the next font, and so on.
Start with the font you want, and end with a generic family, to let the browser pick a similar
font in the generic family, if no other fonts are available.
Note: If the name of a font family is more than one word, it must be in quotation marks,
like: "Times New Roman".
Example:
p{
font-family: "Times New Roman", Times, serif;
}
By default in the CSS box model, the width and height you assign to an element is applied
only to the element's content box. Border-box tells the browser to account for
any border and padding in the values you specify for an element's width and height.
Example:
Include padding and border in the element's total width and height:
#example1 {
box-sizing: border-box;
}
3.8 MARGINS
The margin property sets the margins for an element, and is a shorthand property for the
following properties:
margin-top
margin-right
margin-bottom
margin-left
margin: 10px;
o all four margins are 10px
Example
Set the margin for all four sides of a <p> element to 35 pixels:
p{
margin: 35px;
}
The CSS padding properties are used to generate space around an element's content, inside
of any defined borders. With CSS, you have full control over the padding. There are
properties for setting the padding for each side of an element (top, right, bottom, and left).
CSS has properties for specifying the padding for each side of an element:
padding-top
padding-right
padding-bottom
padding-left
Example: Set different padding for all four sides of a <div> element:
div {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
The position property specifies the type of positioning method used for an element.
There are five different position values:
static
relative
fixed
absolute
sticky
Elements are then positioned using the top, bottom, left, and right properties. However,
these properties will not work unless the position property is set first. They also work
differently depending on the position value.
Example
div.relative {
position: relative;
width: 400px;
height: 200px;
border: 3px solid #73AD21;
}
div.absolute {
position: absolute;
top: 80px;
right: 0;
width: 200px;
height: 100px;
border: 3px solid #73AD21;
}
3.11 CSS2
Cascading Style Sheets Level 2 (CSS2) is the second version of cascading style sheets
developed by W3C. It's a declarative language used to enhance the hyper extensive text
mark-up language. CSS2 is a subset of Cascading Style Sheets Level 1 and has enhanced
capabilities like: Currently, W3C does not provide any CSS2 recommendations. CSS2 have
backward compatibility, so all valid CSS1 is also valid CSS2.
Flexibility. CSS can be applied to content in several ways. The key feature is the
ability to cascade style information specified in: the default UA style sheet, user style
sheets,
Richness. Providing authors with a rich set of rendering effects increases the richness
of the Web as a medium of expression. Designers have been longing for functionality
commonly found e.g. in desktop publishing and slide-show applications.
Alternate language bindings. The set of CSS properties described in this specification
form a consistent formatting model for visual and aural presentations. This
formatting model can be accessed through the CSS language, but bindings to other
languages are also possible. For example, a JavaScript program may dynamically
change the value a certain element's 'color''color' property.
Accessibility. Last, but not least, using CSS will increase accessibility to Web
documents. By retaining textual information in text form, both robots indexing Web
pages and human users will have more options for digesting the content. Users can
provide their personal style sheets if author-suggested style sheets hinder
accessibility.
JavaScript is a scripting language most often used for client-side web development. Client-
side refers to operations that are performed by the client (in our case the client is the
browser) in a client-server relationship. Despite the name, JavaScript is essentially unrelated
to the Java programming language.
Example:
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
3.14.1 VARIABLE
Example
var x = 5;
var y = 6;
var z = x + y;
3.14.2 FUNCTION
Earlier in this tutorial, you learned that functions are declared with the following syntax:
function functionName(parameters) {
// code to be executed
}
Example
function myFunction(a, b) {
return a * b;
}
3.14.3 CONDITION
Very often when you write code, you want to perform different actions for different
decisions.
Statement
Use the if statement to specify a block of JavaScript code to be executed if a condition is true.
Syntax
if (condition) {
// block of code to be executed if the condition is true
}
Example
What we need is a generic solution for repeating code with control over how many times
the code repeats. In JavaScript, this solution is provided in the form of something known as
a loop. There are three kinds of loops we can use to repeat some code:
for loops
while loops
do...while loops
Each of these three loop variations allow us to specify the code we want to repeat (aka loop)
and a way to stop the repetition when a condition is met. In the following sections, we'll
learn all about them.
Example:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Loops!</title>
<style>
</style>
</head>
<body>
<script>
for (var i = 0; i < count; i++) {
saySomething();
}
function saySomething() {
document.writeln("hello!");
}
</script>
</body>
</html>
An alert box is often used if you want to make sure information comes through to the user.
When an alert box pops up, the user will have to click "OK" to proceed.
Syntax
window.alert("sometext");
Example
Confirm Box
A confirm box is often used if you want the user to verify or accept something.
When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.
Syntax
window.confirm("sometext");
Example:
if (confirm("Press a button!")) {
txt = "You pressed OK!";
} else {
Example
The values are written as name : value pairs (name and value separated by a colon)
Example
A car has properties like weight and color, and methods like start and stop:
car.name = car.start()
Fiat
car.drive()
car.model =
500 car.brake()
car.weight = car.stop()
850kg
car.color =
white
The JavaScript specification calls that a host environment. A host environment provides
platform-specific objects and functions additional to the language core. Web browsers give
a means to control web pages. Node.js provides.
HTML DOM?
The HTML DOM is a standard object model and programming interface for HTML. It defines:
DOM manipulation methods allows you to add, edit or delete DOM element(s) in the web
page. Use the selector to get the reference of an element(s) and then
call manipulate methods to edit it. Important DOM manipulation methods: append(),
propend(), before(), after(), remove(), replace All(), wrap() .
The HTML DOM is a standard object model and programming interface for HTML. It defines:
The data entered into a form needs to be in the right format and certain fields need to be
filled in order to effectively use the submitted form. Username, password, contact
information is some details that are mandatory in forms and thus need to be provided by
the user.
<script>
function GEEKFORGEEKS()
{
var name = document.forms["RegForm"]["Name"];
var email = document.forms["RegForm"]["EMail"];
var phone = document.forms["RegForm"]["Telephone"];
var what = document.forms["RegForm"]["Subject"];
if (name.value == "")
{
window.alert("Please enter your name.");
name.focus();
return false;
}
if (address.value == "")
{
window.alert("Please enter your address.");
name.focus();
return false;
}
if (email.value == "")
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (email.value.indexOf("@", 0) < 0)
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (email.value.indexOf(".", 0) < 0)
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (phone.value == "")
{
window.alert("Please enter your telephone number.");
phone.focus();
return false;
}
if (password.value == "")
{
if (what.selectedIndex < 1)
{
alert("Please enter your course.");
what.focus();
return false;
}
return true;
}</script>
3.22 DHTML
You can merge two or more table cells together by using the colspan attribute in a
<td> HTML tag (table data). For example, in the below code is a table with three rows and
three columns. If we wanted to combine the first two cells into one cell, we could use the
colspan="2" attribute in the first <td> tag.
<table>
<tr>
<td colspan="2"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
The <script> element either contains script statements, or it points to an external script file
through the src attribute.
Common uses for JavaScript are image manipulation, form validation, and dynamic changes
of content.
To select an HTML element, JavaScript most often uses the document, get Element By Id
() method.
This JavaScript example writes "Hello JavaScript!" into an HTML element with id="demo":
Example
<Script>
document .get Element ById("demo").inner HTML = "Hello JavaScript!";
</script>
<html>
<head>
<script type="text/javascript">
function changetext(id)
{
id.innerHTML="Ooops!";
}
</script>
</head>
<body>
<h1 onclick="changetext(this)">Click on this text</h1>
</body>
</html>