CS504 - Internet & Web Technology - Unit 3 - Notes - 1596871877
CS504 - Internet & Web Technology - Unit 3 - Notes - 1596871877
CS504 - Internet & Web Technology - Unit 3 - Notes - 1596871877
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.
CSS stands for Cascading Style Sheets
CSS describes how HTML elements are to be displayed on screen, paper, or in other
media
CSS saves a lot of work. It can control the layout of multiple web pages all at once
External style sheets are stored in CSS files
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;
}
Top.
Right.
Bottom.
Left.
Enter any combination of the above
CSS background-image Property
h1 {
color: #00ff00;
}
p.ex {
color: rgb(0,0,255);
}
The text can be 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:
Example :
body {
color: blue;
}
h1 {
color: green;
}
Font Family
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;
}
CSS has properties for specifying the padding for each side of an element:
padding-top
padding-right
padding-bottom
padding-left
inherit - specifies that the padding should be inherited from the parent element
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;
}
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.
Cursors
Dynamic outlines
Capability to control content overflow, clipping
Absolute, fixed and relative positioning
Simplicity. CSS2 is more complex than CSS1, but it remains a simple style language
which is human read- and writable.
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.
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
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.
Use else if to specify a new condition to test, if the first condition is false
If Statement
Syntax
if (condition) {
// block of code to be executed if the condition is true
}
Example
if (hour < 18) {
greeting = "Good day";
}
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>
Alert Box
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");
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 {
txt = "You pressed Cancel!";
}
Example
The values are written as name : value pairs (name and value separated by a colon)
Example
car.name = car.start()
Fiat
car.drive()
car.model =
500 car.brake()
car.weight = car.stop()
850kg
car.color =
white
HTML DOM?
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.
Form validation:
<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"];
var password = document.forms["RegForm"]["Password"];
var address = document.forms["RegForm"]["Address"];
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 == "")
{
window.alert("Please enter your password");
password.focus();
return false;
}
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>
3.24 CSS AND JAVASCRIPT
Common uses for JavaScript are image manipulation, form validation, and dynamic changes
of content.
This JavaScript example writes "Hello JavaScript!" into an HTML element with id="demo":
Example
<Script>
document.getElementById("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>