HTML CSS JS NOTES by ASHOK PATE
HTML CSS JS NOTES by ASHOK PATE
94
2 PG Mates / RoomSharing / Flat Mates React+Springboot+MySql
21
3 Tour and Travel management System React+Springboot+MySql
59
5 HomeRental Booking System React+Springboot+MySql
07
6 Event Management System React+Springboot+MySql
80
8 Agriculture web Project React+Springboot+MySql
9 AirLine Reservation System / Flight booking System React+Springboot+MySql
.in
10 E-commerce web Project React+Springboot+MySql
ys
11 Hospital Management System React+Springboot+MySql
ra
12 E-RTO Driving licence portal React+Springboot+MySql
13 Transpotation Services portal
ar
React+Springboot+MySql
14 Courier Services Portal / Courier Management System React+Springboot+MySql
ith
15 Online Food Delivery Portal React+Springboot+MySql
w
16 Muncipal Corporation Management React+Springboot+MySql
17 Gym Management System de React+Springboot+MySql
co
18 Bike/Car ental System Portal React+Springboot+MySql
19 CharityDonation web project React+Springboot+MySql
20 Movie Booking System React+Springboot+MySql
freelance_Project available to buy contact on 8007592194
21 Job Portal web project React+Springboot+MySql
22 LIC Insurance Portal React+Springboot+MySql
23 Employee Management System React+Springboot+MySql
94
24 Payroll Management System React+Springboot+MySql
25 RealEstate Property Project React+Springboot+MySql
21
26 Marriage Hall Booking Project React+Springboot+MySql
27 Online Student Management portal React+Springboot+MySql
59
28 Resturant management System React+Springboot+MySql
29 Solar Management Project React+Springboot+MySql
07
30 OneStepService LinkLabourContractor React+Springboot+MySql
31 Vehical Service Center Portal React+Springboot+MySql
80
32 E-wallet Banking Project React+Springboot+MySql
33 Blogg Application Project React+Springboot+MySql
34 Car Parking booking Project React+Springboot+MySql
.in
35 OLA Cab Booking Portal React+Springboot+MySql
36 Society management Portal React+Springboot+MySql
ys
37 E-College Portal React+Springboot+MySql
38 FoodWaste Management Donate System React+Springboot+MySql
ra
39 Sports Ground Booking React+Springboot+MySql
ar
40 BloodBank mangement System React+Springboot+MySql
41 Bus Tickit Booking Project React+Springboot+MySql
ith
42 Fruite Delivery Project React+Springboot+MySql
43 Woodworks Bed Shop React+Springboot+MySql
w
44 Online Dairy Product sell Project React+Springboot+MySql
45
46
Online E-Pharma medicine sell Project
FarmerMarketplace Web Project
de
React+Springboot+MySql
React+Springboot+MySql
co
47 Online Cloth Store Project React+Springboot+MySql
48 React+Springboot+MySql
49 React+Springboot+MySql
50 React+Springboot+MySql
https://www.youtube.com/@codewitharrays
94
https://www.instagram.com/codewitharrays/
21
59
07
https://t.me/codewitharrays Group Link: https://t.me/cceesept2023
80
.in
+91 8007592194 +91 9284926333
ys
ra
ar
ith
[email protected]
w
de
co
https://codewitharrays.in/project
HTML
------------------------------------------------------------------------------------------------------------
94
21
59
07
80
Hyper Text Markup Language .in
ys
(HTML)
ra
ar
ith
w
de
co
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
INDEX
Topics Page No
94
3. HTML Head Section
3.1. Meta 4
21
3.2. Doctype 5
3.3. Link 6
59
4. HTML Paragraph 7
07
5. HTML Hyperlinks 10
80
6. HTML Images 11
7. HTML Tables 15
7.1. Cellpadding
7.2. Cellspacing
.in 20
21
ys
8. Special Characters 22
ra
11.1. Textbox 24
11.2. Radio Button 25
de
11.3. Checkboxes 25
11.4. Password 26
co
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
What is HTML?
94
● HTML stands for Hyper Text Markup Language
21
● HTML is not a programming language, it is a markup language
● A markup language is a set of markup tags
● HTML uses markup tags to describe web pages
59
BASIC HTML Page Structure
07
<html>
80
<head>
<title>Page Title</title>
</head>
<body>
<p>
Page Content
.in
</p>
ys
</body>
</html>
ra
HTML Head
ar
According to the HTML standard, only a few tags are legal inside the head
section. These are: <base>, <link>, <meta>, <title>, <style>, and <script>.
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
<head>
<p>This is some text</p>
</head>
In this case the browser has two options:
If you put an HTML element like <h1> or <p> inside a head element like
this, most browsers will display it, even if it is illegal.
94
Should browsers forgive you for errors like this? We don't think so.
Others do.
21
Head Tags
Tag Description
59
<head> Defines information about the document
<title> Defines the document title
07
s<link> Defines a resource reference
<meta> Defines meta information
80
Tag Description
<!DOCTYPE> Defines the document type. This tag goes before the <html> start tag.
HTML also includes a meta element that goes inside the head element. The
ar
Some search engines on the WWW will use the name and content attributes
of the meta tag to index your pages.
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
<meta name="keywords" content="HTML, DHTML, CSS, XML, XHTML, JavaScript"
/>
The intention of the name and content attributes is to describe the
content of a page.
94
<title>Title of the document</title>
</head>
<body>
21
The content of the document......
</body>
59
</html>
07
The doctype declaration should be the very first thing in an HTML document, before the <html>
80
tag.
The doctype declaration is not an HTML tag; it is an instruction to the web browser about what
version of the markup language the page is written in.
.in
The doctype declaration refers to a Document Type Definition (DTD). The DTD specifies the rules
for the markup language, so that the browsers can render the content correctly.
ys
ra
This DTD contains all HTML elements and attributes, but does not include presentational or
deprecated elements (like font). Framesets are not allowed.
w
"http://www.w3.org/TR/html4/strict.dtd">
This DTD contains all HTML elements and attributes, including presentational and deprecated
elements (like font). Framesets are not allowed.
This DTD is equal to HTML 4.01 Transitional, but allows the use of frameset content.
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
This DTD contains all HTML elements and attributes, but does not include presentational or
deprecated elements (like font). Framesets are not allowed. The markup must also be written as
well-formed XML.
94
This DTD contains all HTML elements and attributes, including presentational and deprecated
elements (like font). Framesets are not allowed. The markup must also be written as well-formed
21
XML.
59
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
07
XHTML 1.0 Frameset
This DTD is equal to XHTML 1.0 Transitional, but allows the use of frameset content.
80
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
external resource.
de
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
● provides a title for the page when it is added to favorites
● displays a title for the page in search-engine results
HTML Tags
94
is the end tag
● Start and end tags are also called opening tags and closing
21
tags.
59
HTM or HTML Extension?
When you save an HTML file, you can use either the .htm or
07
the .html extension.
80
HTML Headings
Example:
.in
ys
<h1>This is a heading</h1>
ra
<h2>This is a heading</h2>
<h3>This is a heading</h3>
ar
HTML Paragraphs
ith
Example:
co
<p>This is a paragraph</p>
<p>This is another paragraph</p>
HTML Links
Example:
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
<a href="http://www.infinitech.in">This is a link</a>
HTML Images
Example:
94
HTML Comments
21
Comments can be inserted in the HTML code to make it more
readable and understandable. Comments are ignored by the
59
browser and are not displayed.
07
Example:- <!-- This is a comment -->
80
Note: There is an exclamation point after the opening
bracket, but not before the closing bracket.
Use the <br /> tag if you want a line break (a new line)
de
Example:-
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
In XHTML, XML, and future versions of HTML, HTML elements with no
end tag (closing tag) are not allowed.
94
This text is italic
21
This is computer output
This is subscript
and superscript
59
HTML Formatting Tags
07
HTML uses tags like <b> and <i> for formatting output, like
bold or italic text.
80
These HTML tags are called formatting tags.
HTML Links
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
In web terms, a hyperlink is a reference (an address) to a
resource on the web.
94
hyperlinks and anchors.
21
We will use the term HTML link when the <a> element points
to a resource, and the term HTML anchor when the <a>
59
elements defines an address inside a document..
An HTML Link
07
Link syntax:
80
<a href="url">Link text</a>
The start tag contains attributes about the link.
Site!</a>
The target Attribute
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
Example
<a href="http://www.infinitech.in/"
target="_blank">Visit Infinitech Website!</a>
94
Named anchor are not displayed in any special way. They are
invisible to the reader.
21
Named anchor syntax:
59
<a name="label">Any content</a>
The link syntax to a named anchor:
07
<a href="#label">Any content</a>
80
The # in the href attribute defines a link to a named
anchor.
Example: .in
ys
A named anchor inside an HTML document:
ra
<a href="#tips">
ith
<a href="http://www.infinitech.in/html_tutorial.htm#tips">
Jump to the Useful Tips Section</a>
co
HTML IMAGES :
Inserting Images:
<html>
<body>
<p>
An image:
<img src="constr4.gif"
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
width="144" height="50">
</p>
<p>
A moving image:
<img src="hackanm.gif"
width="48" height="48">
</p>
<p>
Note that the syntax of inserting a moving image is no different from
that of a non-moving image.
94
</p>
21
</body>
</html>
59
Insert Images From Different Locations:
<html>
07
<body>
80
<p>An image from SMGSM:</p>
<img src="http://smgsm.com/images/logo.jpg">
</body>
</html> .in
The Image Tag and the Src Attribute
ys
your page.
co
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
The browser puts the image where the image tag occurs in
the document. If you put an image tag between two
paragraphs, the browser shows the first paragraph, then the
image, and then the second paragraph.
94
<img src="boat.gif" alt="Big Boat" />
21
The "alt" attribute tells the reader what he or she is
missing on a page if the browser can't load images. The
59
browser will then display the alternate text instead of the
image. It is a good practice to include the "alt" attribute
for each image on a page, to improve the display and
07
usefulness of your document for people who have text-only
browsers.
80
Basic Notes - Useful Tips
If an HTML file contains ten images - eleven files are
.in
required to display the page right. Loading images take
ys
time, so my best advice is: Use images carefully.
ra
Background Images:
ar
<html>
ith
<body background="background.jpg">
<h3>Look: A background image!</h3>
<p>If the image is smaller than the page, the image will repeat
w
itself.</p>
</body>
de
</html>
co
Alignment of Image:
<html>
<body>
<p>
An image
<img src="hackanm.gif"
align="bottom" width="48" height="48">
in the text
</p>
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
<p>
An image
<img src ="hackanm.gif"
align="middle" width="48" height="48">
in the text
</p>
<p>
An image
<img src ="hackanm.gif"
align="top" width="48" height="48">
94
in the text
</p>
21
<p>Note that bottom alignment is the default alignment</p>
59
<p>
An image
<img src ="hackanm.gif"
07
width="48" height="48">
in the text
80
</p>
<p>
<img src ="hackanm.gif"
width="48" height="48">
An image before the text
.in
</p>
ys
<p>
ra
width="48" height="48">
</p>
ith
</body>
</html>
w
<html>
co
<body>
<p>
<img src ="hackanm.gif"
align ="left" width="48" height="48" alt=”An Image”>
A paragraph with an image. The align attribute of the image is set to
"left". The image will float to the left of this text.
</p>
<p>
<img src ="hackanm.gif"
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
align ="right" width="58" height="58" alt=”An Image”>
A paragraph with an image. The align attribute of the image is set to
"right". The image will float to the right of this text.
</p>
<p>
You can also use an image as a link:
<a href="lastpage.htm">
<img border="0" src="buttonnext.gif" width="65" height="38">
</a>
</p>
94
</body>
</html>
21
Note: You can make a picture larger or smaller changing the values in the
"height" and "width" attributes of the img tag.
59
ALT Tag: The "alt" attribute tells the reader what he or she is missing
on a page if the browser can't load images. It is a good practice to
07
include the "alt" attribute for each image on a page.
80
HTML TABLES
Tables are defined with the <table> tag. A table is divided into rows
.in
(with the <tr> tag), and each row is divided into data cells (with the
ys
<td> tag). The letters td stands for "table data," which is the content
of a data cell. A data cell can contain text, images, lists, paragraphs,
ra
<html>
co
<body>
<p>
Each table starts with a table tag.
Each table row starts with a tr tag.
Each table data starts with a td tag.
</p>
<h4>One column:</h4>
<table border="1">
<tr>
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
<td>100</td>
</tr>
</table>
94
<h4>Two rows and three columns:</h4>
21
<table border="8">
<tr>
<td>100</td>
59
<td>200</td>
<td>300</td>
</tr>
07
<tr>
<td>400</td>
80
<td>500</td>
<td>600</td>
</tr>
</table>
</body>
.in
</html>
ys
Headings in a Table
ra
ar
<table border="1">
<tr>
w
<th>Heading</th>
<th>Another Heading</th>
de
</tr>
<tr>
co
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
Heading Another Heading
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
Empty Cells in a Table
<table border="1">
<tr>
94
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
21
</tr>
<tr>
59
<td>row 2, cell 1</td>
<td></td>
07
</tr>
</table>
80
How it looks in a browser:
<table border="1">
ith
<tr>
<td>row 1, cell 1</td>
w
</tr>
<tr>
<td>row 2, cell 1</td>
co
<td> </td>
</tr>
</table>
How it looks in a browser:
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
The <thead>,<tbody> and <tfoot> elements are seldom used, because of bad
browser support. Expect this to change in future versions of XHTML.
Headings in a table
<html>
<body>
94
<h4>Table headers:</h4>
21
<table border="1">
<tr>
<th>Name</th>
59
</tr>
<tr>
07
<td>Bill Gates</td>
</tr>
</table>
80
</body>
</html>
<html>
<body>
ith
<table border="6">
<caption>My Caption</caption>
w
<tr>
<td>100</td>
de
<td>200</td>
<td>300</td>
</tr>
co
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
</body>
</html>
Output:
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
My Caption
100 200 300
400 500 600
<table border="1">
<tr>
<th>Name</th>
94
<th colspan="2">Telephone</th>
</tr>
<tr>
21
<td>Bill Gates</td>
<td>555 77 854</td>
59
<td>555 77 855</td>
</tr>
</table>
07
Output:
80
Name Telephone
Bill Gates 555 77 854 555 77 855
<table border="1">
<tr>
.in
ys
<th>First Name:</th>
<td>Bill Gates</td>
</tr>
ra
<tr>
<th rowspan="2">Telephone:</th>
ar
<td>555 77 854</td>
</tr>
ith
<tr>
<td>555 77 855</td>
w
</tr>
</table>
de
555 77 854
Telephone:
555 77 855
<table border="1">
<tr>
<td>
<p>This is a paragraph</p>
<p>This is another paragraph</p>
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
</td>
<td>This cell contains a table:
<table border="1">
<tr>
<td>A</td>
<td>B</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
</tr>
</table>
94
</td>
</tr>
21
<tr>
<td>This cell contains a list
<ul>
59
<li>apples</li>
<li>bananas</li>
<li>pineapples</li>
07
</ul>
</td>
80
<td>HELLO</td>
</tr>
</table>
<td>Row</td>
</tr>
ar
<tr>
<td>Second</td>
ith
<td>Row</td>
</tr>
w
</table>
de
<h4>With cellpadding:</h4>
<table border="1"
cellpadding="10">
co
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
Without cellpadding:
First Row
Second Row
With cellpadding:
First Row
Second Row
94
21
Cell spacing
59
<h4>Without cellspacing:</h4>
<table border="1">
07
<tr>
<td>First</td>
<td>Row</td>
80
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
.in
ys
<h4>With cellspacing:</h4>
ra
<table border="1"
cellspacing="10">
<tr>
ar
<td>First</td>
<td>Row</td>
ith
</tr>
<tr>
w
<td>Second</td>
<td>Row</td>
de
</tr>
</table>
co
Without cellspacing:
First Row
Second Row
With cellspacing:
First Row
Second Row
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
Add a background color or a background image to a table
94
<td>Row</td>
</tr>
</table>
21
<h4>A background image:</h4>
<table border="1"
background="bgdesert.jpg">
59
<tr>
<td>First</td>
07
<td>Row</td>
</tr>
<tr>
80
<td>Second</td>
<td>Row</td>
</tr>
</table>
A background color:
.in
ys
First Row
Second Row
ra
ar
<table border="1">
w
<tr>
<td bgcolor="red">First</td>
de
<td>Row</td>
</tr>
<tr>
co
<td
background="bgdesert.jpg">
Second</td>
<td>Row</td>
</tr>
</table>
Cell backgrounds:
First Row
Second Row
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
Special Characters
Code Symbol Description
™ ™ Trademark
& & Ampersand
® ® Registered trademark
© © Copyright
94
† † Dagger
» » Right pointing double angle
21
quotation mark
« « Left pointing double angle
59
quotation mark
— — Em-dash
07
° 30° Degree
80
¼ ¼ Quarter
½ ½ Half
¾
·
¾
·
Three quarters
Middle dot
.in
ys
¡ ¡ Inverted exclamation mark
ra
Unordered Lists
ith
An unordered list starts with the <ul> tag. Each list item
starts with the <li> tag.
co
<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>
Here is how it looks in a browser:
● Coffee
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
● Milk
Ordered Lists
94
marked with numbers.
21
An ordered list starts with the <ol> tag. Each list item
starts with the <li> tag.
59
<ol>
<li>Coffee</li>
07
<li>Milk</li>
</ol>
80
Here is how it looks in a browser:
1. Coffee
2. Milk .in
ys
Inside a list item you can put paragraphs, line breaks,
images, links, other lists, etc.
ra
Forms
ith
w
<form>
.
input elements
.
</form>
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
Input
The most used form tag is the <input> tag. The type of
input is specified with the type attribute. The most
commonly used input types are explained below.
Text Fields
Text fields are used when you want the user to type
94
letters, numbers, etc. in a form.
<form>
21
First name:
<input type="text" name="firstname" />
59
<br />
Last name:
07
<input type="text" name="lastname" />
</form>
80
How it looks in a browser:
Note that the form itself is not visible. Also note that in
ar
Radio Buttons
w
de
Radio Buttons are used when you want the user to select one
of a limited number of choices.
co
<form>
<input type="radio" name="sex" value="male" /> Male
<br />
<input type="radio" name="sex" value="female" /> Female
</form>
How it looks in a browser:
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
Male
Female
Checkboxes
Checkboxes are used when you want the user to select one or
94
more options of a limited number of choices.
21
<form>
I have a bike:
59
<input type="checkbox" name="vehicle" value="Bike" />
<br />
07
I have a car:
<input type="checkbox" name="vehicle" value="Car" />
<br />
80
I have an airplane:
<input type="checkbox" name="vehicle" value="Airplane" />
</form>
How it looks in a browser:
.in
ys
ra
I have a bike:
ar
I have a car:
I have an airplane:
ith
w
de
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
Username:
<input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
Input Type Password in HTML
94
Example:
21
<html>
<body>
59
<form action="">
07
Username:
80
<input type="text" name="user">
<br>
Password:
.in
ys
<input type="password" name="password">
ra
</form>
ar
</body>
ith
</html>
w
Output:
de
co
Example:
<select name="cars">
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</form>
94
</body>
21
</html>
59
Output:
07
80
Note : If in option tag selected =”selected” is specified then specific
value will be selected by default.
Example: .in
ys
<option value="fiat" selected="selected">Fiat</option>
ra
Output:
ar
ith
Textarea in HTML
w
Example:
de
</textarea>
Output:
------------------------------------------------------------------------------------------------------------
HTML
------------------------------------------------------------------------------------------------------------
94
21
59
07
80
.in
ys
ra
ar
ith
w
de
co
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
94
21
59
07
80
Cascading Style Sheet .in
ys
(CSS)
ra
ar
ith
w
de
co
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
INDEX
Topics Page No
2. CSS Syntax 4
94
3. CSS Grouping 5
21
4. CSS Selector 5
59
5. Comments 6
07
6. CSS Types 7
7. CSS Background 9
80
8. CSS Text 11
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
What is CSS?
94
● Styles define how to display HTML elements
● Styles are normally stored in Style Sheets
21
● Styles were added to HTML 4.0 to solve a problem
● External Style Sheets can save a lot of work
59
● External Style Sheets are stored in CSS files
● Multiple style definitions will cascade into one
07
Why Css?
80
The original HTML was never intended to contain tags for formatting a
document. HTML tags were intended to define the content of a document,
like:
<p>This is a paragraph.</p>
.in
ys
<h1>This is a heading</h1>
ra
When tags like <font> and color attributes were added to the HTML 3.2
specification, it started a nightmare for web developers. Development of
ar
large web sites where fonts and color information had to be added to
every single Web page, became a long, expensive and unduly painful
ith
process.
w
To solve this problem, the World Wide Web Consortium (W3C) - responsible
for standardizing HTML - created CSS in addition to HTML 4.0.
de
With HTML 4.0, all formatting can be removed from the HTML document and
stored in a separate CSS file.
co
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Styles are normally saved in external .css files. External style sheets
enable you to change the appearance and layout of all the pages in a Web
site, just by editing one single CSS document!
94
● inside the head section of an HTML page
● in an external CSS file
21
Tip: Even multiple external style sheets can be referenced inside a
single HTML document.
59
Cascading order - What style will be used when there is more than one
07
style specified for an HTML element?
Generally speaking we can say that all the styles will "cascade" into a
80
new "virtual" style sheet by the following rules, where number four has
the highest priority:
So, an inline style (inside an HTML element) has the highest priority,
which means that it will override a style defined inside the <head> tag,
ar
If the link to the external style sheet is placed after the internal
style sheet in HTML <head>, the external style sheet will override the
internal style sheet!
w
de
CSS syntax
co
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 a colon, and surrounded
by curly braces:
body {color:black}
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Note: If the value is multiple words, put quotes around the value:
p {font-family:"sans serif"}
Note: If you want to specify more than one property, you must separate
each property with a semicolon. The example below shows how to define a
center aligned paragraph, with a red text color:
p {text-align:center;color:red}
To make the style definitions more readable, you can describe one
property on each line, like this:
94
p
{
text-align:center;
21
color:black;
font-family:arial
}
59
Grouping
07
You can group selectors. Separate each selector with a comma. In the
example below we have grouped all the header elements. All header
80
elements will be displayed in green text color:
h1,h2,h3,h4,h5,h6
{
color:green
}
.in
The class Selector
ys
With the class selector you can define different styles for the same type
ra
of HTML element.
ar
Say that you would like to have two types of paragraphs in your document:
one right-aligned paragraph, and one center-aligned paragraph. Here is
ith
p.right {text-align:right}
p.center {text-align:center}
de
You can also omit the tag name in the selector to define a style that
will be used by all HTML elements that have a certain class. In the
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
example below, all HTML elements with class="center" will be
center-aligned:
.center {text-align:center}
In the code below both the h1 element and the p element have
class="center". This means that both elements will follow the rules in
the ".center" selector:
94
Mozilla/Firefox.
21
You can also apply styles to HTML elements with particular attributes.
59
The style rule below will match all input elements that have a type
attribute with a value of "text":
07
input[type="text"] {background-color:blue}
80
The id Selector
You can also define styles for HTML elements with the id selector. The id
selector is defined as #. .in
The style rule below will match the element that has an id attribute with
ys
a value of "green":
ra
#green {color:green}
The style rule below will match the p element that has an id with a value
ar
of "para1":
ith
p#para1
{
text-align:center;
w
color:red
de
}
Do NOT start an ID name with a number! It will not work in
Mozilla/Firefox.
co
CSS Comments
Comments are used to explain your code, and may help you when you edit
the source code at a later date. A comment will be ignored by browsers. A
CSS comment begins with "/*", and ends with "*/", like this:
/*This is a comment*/
p
{
text-align:center;
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
/*This is another comment*/
color:black;
font-family:arial
}
CSS Types
When a browser reads a style sheet, it will format the document according
94
to it. There are three ways of inserting a style sheet:
21
External Style Sheet
An external style sheet is ideal when the style is applied to many pages.
59
With an external style sheet, you can change the look of an entire Web
site by changing one file. Each page must link to the style sheet using
07
the <link> tag. The <link> tag goes inside the head section:
<head>
80
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
The browser will read the style definitions from the file mystyle.css,
and format the document according to it. .in
An external style sheet can be written in any text editor. The file
ys
should not contain any html tags. Your style sheet should be saved with a
.css extension. An example of a style sheet file is shown below:
ra
hr {color:sienna}
ar
p {margin-left:20px}
body {background-image:url("images/back40.gif")}
ith
Do not leave spaces between the property value and the units!
"margin-left:20 px" (instead of "margin-left:20px") will only work in
IE6, but it will not work in Firefox or Opera.
w
de
<head>
<style type="text/css">
hr {color:sienna}
p {margin-left:20px}
body {background-image:url("images/back40.gif")}
</style>
</head>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
The browser will now read the style definitions, and format the document
according to it.
Note: A browser normally ignores unknown tags. This means that an old
browser that does not support styles, will ignore the <style> tag, but
the content of the <style> tag will be displayed on the page. It is
possible to prevent an old browser from displaying the content by hiding
it in the HTML comment element:
<head>
<style type="text/css">
94
<!--
hr {color:sienna}
p {margin-left:20px}
21
body {background-image:url("images/back40.gif")}
-->
</style>
59
</head>
Inline Styles
07
An inline style loses many of the advantages of style sheets by mixing
content with presentation. Use this method sparingly, such as when a
80
style is to be applied to a single occurrence of an element.
To use inline styles you use the style attribute in the relevant tag. The
.in
style attribute can contain any CSS property. The example shows how to
change the color and the left margin of a paragraph:
ys
<p style="color:sienna;margin-left:20px">This is a paragraph.</p>
Multiple Style Sheets
ra
If some properties have been set for the same selector in different style
ar
sheets, the values will be inherited from the more specific style sheet.
ith
For example, an external style sheet has these properties for the h3
selector:
w
h3
de
{
color:red;
co
text-align:left;
font-size:8pt
}
And an internal style sheet has these properties for the h3 selector:
h3
{
text-align:right;
font-size:20pt
}
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
If the page with the internal style sheet also links to the external
style sheet the properties for h3 will be:
color:red;
text-align:right;
font-size:20pt
The color is inherited from the external style sheet and the
text-alignment and the font-size is replaced by the internal style sheet.
CSS Background
94
1. Color as a background
<style type="text/css">
21
body
59
{
07
background-color:yellow;
80
}
h1
{
.in
ys
background-color:#00ff00;
ra
}
ar
p
ith
{
w
background-color:rgb(255,0,255);
de
}
co
</style>
2. Image as a background
<style type="text/css">
body {background-image:url('paper.gif')}
</style>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
<style type="text/css">
body
94
{
background-image:url('paper.gif');
background-repeat:repeat-x;
21
}
</style>
59
Background Image Horizontal Repeat
07
<style type="text/css">
body
{
80
background-image:url('paper.gif');
background-repeat:repeat-y;
}
</style> .in
Display a Background Image only one time
ys
<style type="text/css">
ra
body
{
background-image:url('paper.gif');
ar
background-repeat:no-repeat;
}
ith
</style>
w
4. Image as a background
de
<style type="text/css">
co
body
{
background-image:url('smiley.gif');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
</style>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Background-attachment: Sets whether a background image is fixed or
scrolls with the rest of the pages. Default value is Scroll.
<style type="text/css">
body {background-image:url('paper.gif')}
</style>
Property Values
94
Value Description
top left If you only specify one keyword, the second value will be
21
top center "center". Default value is: 0% 0%
top right
59
center left
center center
center right
07
bottom left
bottom center
bottom right
80
x% y% The first value is the horizontal position and the second
value is the vertical. The top left corner is 0% 0%. The
right bottom corner is 100% 100%. If you only specify one
xpos ypos
value, the other value will be 50%. .in
The first value is the horizontal position and the second
value is the vertical. The top left corner is 0 0. Units
ys
can be pixels (0px 0px) or any other CSS units. If you
only specify one value, the other value will be 50%. You
ra
Example:
w
<style type="text/css">
de
body
{
background-image: url('smiley.gif');
co
background-repeat: no-repeat;
background-attachment:fixed;
background-position: 0% 20%;
background-position: 50px 100px;
}
</style>
CSS Text
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
1. Text Color
The color property is used to set the color of the text. The color can be
set by:
94
Example
body {color:blue}
21
h1 {color:#00ff00}
h2 {color:rgb(255,0,0)}
59
2. Text Alignment
07
The text-align property is used to set the horizontal alignment of a
text.
80
Text can be centered, or aligned to the left or right, or justified.
<html>
ar
<head>
ith
<style type="text/css">
w
h1 {text-align:center}
de
p.date {text-align:right}
co
p.main {text-align:justify}
</style>
</head>
<body>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
<p class="date">May, 2009</p>
</body>
</html>
94
Note: Try to resize the browser window to see how justify works.
3. Text Decoration
21
The text-decoration property is used to set or remove decorations from
59
text.
07
The text-decoration property is mostly used to remove underlines from
links for design purposes:
80
Example:
<style type="text/css">
h1 {text-decoration:overline}
.in
ys
h2 {text-decoration:line-through}
ra
h3 {text-decoration:underline}
ar
h4 {text-decoration:blink}
ith
</style>
w
4. Text Transformation
co
Example:
<html>
<head>
<style type="text/css">
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
p.uppercase {text-transform:uppercase}
p.lowercase {text-transform:lowercase}
p.capitalize {text-transform:capitalize}
</style>
</head>
<body>
<p class="uppercase">This is some text in a paragraph</p>
<p class="lowercase">This is some text in a paragraph</p>
<p class="capitalize">This is some text in a paragraph</p>
</body>
</html>
94
5. Text Indentation
21
The text-indentation property is used to specify the indentation of the
first line of a text.
59
Example:
07
<html>
80
<head>
<style type="text/css">
p {text-indent:50px}
</style>
</head> .in
ys
<body>
<p>In my younger and more vulnerable years my father gave me some advice
that I've been turning over in my mind ever since.</p>
ra
</body>
</html>
ar
value will decrease the space while positive value will increase the
space.
de
Example:
co
<html>
<head>
<style type="text/css">
h1 {letter-spacing: -3px}
h4 {letter-spacing: 0.5cm}
</style>
</head>
<body>
<h1>This is header 1</h1>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
<h4>This is header 4</h4>
</body>
</html>
This property is used to specify the space between lines. Negative value
will decrease the space while positive value will increase the space.
Example:
94
<html>
<head>
<style type="text/css">
21
p.small {line-height: 90%}
p.big {line-height: 20px}
</style>
59
</head>
07
<body>
<p>
This is a paragraph with a standard line-height.
80
This is a paragraph with a standard line-height.
This is a paragraph with a standard line-height.
</p>
<p class="small">
This is a paragraph with a smaller line-height.
.in
ys
This is a paragraph with a smaller line-height.
This is a paragraph with a smaller line-height.
This is a paragraph with a smaller line-height.
ra
</p>
ar
<p class="big">
This is a paragraph with a bigger line-height.
ith
</body>
</html>
co
Note: line-height can be given in % and pixel. The default line height in
most browsers is about 110% to 120%.
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
rtl: Text will start from left side.
Example:
<html>
<head>
<style type="text/css">
div.one
{
direction:rtl;
}
div.two
94
{
direction:ltr;
21
}
</style>
</head>
59
<body>
<div class="one">Some text. Right-to-left direction.</div>
07
<div class="two">Some text. Left-to-right direction.</div>
</body>
80
</html>
.in
This property is used to specify the white space between words. Positive
value increases the space while negative value decreases the space.
ys
Example:
ra
<html>
<head>
ar
<style type="text/css">
p
ith
{
word-spacing:30px;
w
}
</style>
de
</head>
<body>
co
<p>
This is some text. This is some text.
</p>
</body>
</html>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
White-space: nowrap – text will not wrap horizontal scroll will be
visible.
Example:
<html>
<head>
<style type="text/css">
94
p
{
white-space:nowrap;
21
}
</style>
59
</head>
<body>
07
<p>
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
80
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>
</body>
</html>
.in
ys
<style type="text/css">
p
ra
{
white-space:nowrap;
ar
}
</style>
ith
CSS Font
w
1. Font Family
de
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 font-family: "Times New Roman".
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Example:
94
● oblique - The text is "leaning" (oblique is very similar to italic,
but less supported)
21
Example:
59
<html>
07
<head>
80
<style type="text/css">
p.normal {font-style:normal}
p.italic {font-style:italic}
.in
ys
p.oblique {font-style:oblique}
ra
</style>
ar
</head>
ith
<body>
w
</body>
</html>
3. Font Size
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Absolute size:
94
Relative size:
21
● Allows a user to change the text size in browsers
59
Note: If you do not specify a font size, the default size for normal
text, like paragraphs, is 16px (16px=1em).
07
Example:
80
<html>
<head>
<style>
.in
ys
h1 {font-size:40px}
ra
h2 {font-size:30px}
ar
p {font-size:14px}
ith
</style>
w
</head>
de
<body>
co
<p>This is a paragraph.</p>
</body>
</html>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
4. Why font Size in em ?
To avoid the resizing problem with Internet Explorer, many developers use
em instead of pixels.
1em is equal to the current font size. The default text size in browsers
is 16px. So, the default size of 1em is 16px.
94
16=em
pixels/
Example:
21
h1 {font-size:2.5em} /* 40px/16=2.5em */
59
5. Font Weight
07
Sets the weight of a font.
Values: normal,bold,bolder,lighter,100,200,300,400,500,600,700,800,900
80
Example:
<html> .in
<head>
ys
<style type="text/css">
ra
p.normal {font-weight:normal}
ar
p.thick {font-weight:bold}
ith
p.thicker {font-weight:900}
w
de
</style>
</head>
co
<body>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
</body>
</html>
6. Font Variant
Example:
<html>
94
<head>
21
<style type="text/css">
59
p.normal {font-variant:normal}
07
p.small {font-variant:small-caps}
80
</style>
</head>
<body> .in
ys
<p class="normal">This is a paragraph.</p>
ra
</body>
ith
</html>
CSS Units
w
de
Measurements
Unit Description
co
% percentage
in inch
cm centimeter
mm millimeter
em 1em is equal to the current font size. 2em means 2
times the size of the current font. E.g., if an element
is displayed with a font of 12 pt, then '2em' is 24 pt.
The 'em' is a very useful unit in CSS, since it can
adapt automatically to the font that the reader uses
ex one ex is the x-height of a font (x-height is usually
about half the font-size)
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
pt point (1 pt is the same as 1/72 inch)
pc pica (1 pc is the same as 12 points)
px pixels (a dot on the computer screen)
Colors
Unit Description
color_name A color name (e.g. red)
rgb(x,x,x) An RGB value (e.g. rgb(255,0,0))
rgb(x%, x%, x%) An RGB percentage value (e.g. rgb(100%,0%,0%))
#rrggbb A HEX number (e.g. #ff0000)
CSS Tables
94
1. Set the layout of a table
21
Example:
59
<html>
07
<head>
<style type="text/css">
80
table.ex1 {table-layout:auto}
</head>
ra
<body>
ar
ith
<tr>
w
de
<td width="5%">1000000000000000000000000000</td>
<td width="95%">10000000</td>
co
</tr>
</table>
<br />
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
<tr>
<td width="5%">1000000000000000000000000000</td>
<td width="95%">10000000</td>
</tr>
</table>
</body>
94
</html>
21
2. Collapse a table border
59
Sets whether the table borders are collapsed into a single border or
detached as in standard HTML
07
Example:
80
<html>
<head>
<style type="text/css">
.in
ys
table {border-collapse:collapse}
ra
</style>
ar
</head>
ith
<body>
w
<table border="1">
de
<tr>
co
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
<td>Griffin</td>
</tr>
</table>
</body>
</html>
94
Sets whether or not to show empty cells in a table (only for the
21
"separated borders" model)
Example:
59
<html>
07
<head>
80
<style type="text/css">
table
{
.in
ys
border-collapse:separate;
ra
empty-cells:hide;
ar
}
ith
</style>
w
</head>
de
<body>
co
<table border="1">
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
<tr>
<td>Lois</td>
<td></td>
</tr>
</table>
</body>
94
</html>
21
CSS Image Opacity
59
Note: This is not yet a CSS standard. However, it works in all modern
browsers, and is a part of the W3C CSS 3 recommendation.
07
1. Transparent Image
80
<img src="klematis.jpg" width="150" height="113" alt="klematis"
style="opacity:0.4;filter:alpha(opacity=40)" />
onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40" />
The syntax for this in Firefox is: this.style.opacity=1 and the syntax in
IE is: this.filters.alpha.opacity=100.
When the mouse pointer moves away from the image, we want the image to be
transparent again. This is done in the onmouseout attribute.
CSS Cursor
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
This property displays different types of cursor by moving on the text.
Example:
<html>
<body>
94
<span style="cursor:crosshair">crosshair</span><br />
21
<span style="cursor:default">default</span><br />
59
<span style="cursor:e-resize">e-resize</span><br />
07
<span style="cursor:help">help</span><br />
80
<span style="cursor:move">move</span><br />
</body>
</html>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
CSS Invisible Tags
Example:
<style type="text/css">
h1.visible {visibility:visible}
94
h1.hidden {visibility:hidden}
21
</style>
59
<body>
07
**<h1 class="hidden">This is an invisible heading</h1>
80
</body>
<head>
ar
<style type="text/css">
ith
ul
w
{
de
float:left;
co
width:100%;
padding:0;
margin:0;
list-style-type:none;
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
}
float:left;
width:6em;
text-decoration:none;
94
color:white;
21
background-color:#aaaaaa;
59
padding:0.2em 0.6em;
07
border-right:1px solid white;
80
}
a:hover {background-color:#ff3300}
li {display:inline} .in
ys
</style>
ra
</head>
ar
<body>
ith
<ul>
</ul>
</body>
</html>
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Output:
CSS Margin
The margin clears an area around an element (outside the border). The
margin does not have a background color, and is completely transparent.
The top, right, bottom, and left margin can be changed independently
94
using separate properties. A shorthand margin property can also be used,
to change all margins at once.
21
1.Possible Values
59
Value Description
auto The browser sets the margin.
07
The result of this is dependant of the browser
length Defines a fixed margin (in pixels, pt, em, etc.)
% Defines a margin in % of the containing element
80
It is possible to use negative values, to overlap content.
Example:
.in
ys
margin-top:100px;
margin-bottom:100px;
ra
margin-right:50px;
margin-left:50px;
ar
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
o right and left margins are 50px
o bottom margin is 75px
● margin:25px 50px;
o top and bottom margins are 25px
o right and left margins are 50px
94
● margin:25px;
o all four margins are 25px
21
59
Note: Margin can be set in cm and %.
07
CSS Border
1. Border Style
80
The border-style property specifies what kind of border to display.
None of the other border properties will have any effect unless
border-style is set.
.in
ys
border-style Values
ra
double: Defines two borders. The width of the two borders are the same as
co
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Example:
<style type="text/css">
94
p.none {border-style:none}
21
p.dotted {border-style:dotted}
p.dashed {border-style:dashed}
59
p.solid {border-style:solid}
07
p.double {border-style:double}
80
p.groove {border-style:groove}
p.ridge {border-style:ridge}
p.inset {border-style:inset}
.in
ys
p.outset {border-style:outset}
ra
p.hidden {border-style:hidden}
ar
</style>
ith
2. Border width
w
Note: The "border-width" property does not work if it is used alone. Use
the "border-style" property to set the borders first.
Example:
p.one
{
border-style:solid;
border-width:5px;
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
}
p.two
{
border-style:solid;
border-width:medium;
}
3. Border color
The border-color property is used to set the color of the border. The
color can be set by:
94
● name - specify a color name, like "red"
● RGB - specify a RGB value, like "rgb(255,0,0)"
21
● Hex - specify a hex value, like "#ff0000"
59
You can also set the border color to "transparent".
Note: The "border-color" property does not work if it is used alone. Use
07
the "border-style" property to set the borders first.
80
Example:
p.one
{
border-style:solid;
border-color:red;
.in
}
ys
p.two
{
ra
border-style:solid;
border-color:#98bf21;
ar
}
ith
Example:
co
p
{
border-top-style:dotted;
border-right-style:solid;
border-bottom-style:dotted;
border-left-style:solid;
}
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
o top border is dotted
o right border is solid
o bottom border is double
o left border is dashed
94
● border-style:dotted solid;
o top and bottom borders are dotted
21
o right and left borders are solid
● border-style:dotted;
59
o all four borders are dotted
07
The border-style property is used in the example above. However, it also
works with border-width and border-color.
80
hen using the border property, the orders of the values are:
Note: W
● border-width
●
●
border-style
border-color
.in
ys
It does not matter if one of the values above are missing (although,
border-style is required), as long as the rest are in the specified
ra
order.
ar
The number in the "CSS" column indicates in which CSS version the
property is defined (CSS1 or CSS2).
w
de
border-color
border-bottom Sets all the bottom border border-bottom-wi 1
properties in one declaration dth
border-bottom-st
yle
border-bottom-co
lor
border-bottom-colo Sets the color of the bottom border-color 2
r border
border-bottom-styl Sets the style of the bottom border-style 2
e border
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
border-bottom-widt Sets the width of the bottom border-width 1
h border
border-color Sets the color of the four color_name 1
borders hex_number
rgb_number
transparent
inherit
border-left Sets all the left border border-left-widt 1
properties in one declaration h
border-left-styl
e
border-left-colo
94
r
border-left-color Sets the color of the left border border-color 2
21
border-left-style Sets the style of the left border border-style 2
border-left-width Sets the width of the left border border-width 1
border-right Sets all the right border border-right-wid 1
59
properties in one declaration th
border-right-sty
07
le
border-right-col
or
80
border-right-color Sets the color of the right border-color 2
border
border-right-style Sets the style of the right border-style 2
border
border-right-width Sets the width of the right
border
border-width
.in 1
ys
border-style Sets the style of the four none 1
borders hidden
ra
dotted
dashed
solid
ar
double
groove
ith
ridge
inset
w
outset
inherit
de
border-top-color
border-top-color Sets the color of the top border border-color 2
border-top-style Sets the style of the top border border-style 2
border-top-width Sets the width of the top border border-width 1
border-width Sets the width of the four thin 1
borders medium
thick
length
inherit
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
CSS Padding
The padding clears an area around the content (inside the border) of an
element. The padding is affected by the background color of the element.
The top, right, bottom, and left padding can be changed independently
using separate properties. A shorthand padding property can also be used,
to change all paddings at once.
Possible Values
94
Value Description
21
length Defines a fixed padding (in pixels, pt, em, etc.)
% Defines a padding in % of the containing element
Padding - Individual sides
59
In CSS, it is possible to specify different padding for different sides:
07
Example
80
padding-top:25px;
padding-bottom:25px;
padding-right:50px;
padding-left:50px; .in
Padding - Shorthand property
ys
To shorten the code, it is possible to specify all the padding properties
ra
Example
w
padding:25px 50px;
de
● padding:25px 50px;
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
o top and bottom paddings are 25px
o right and left paddings are 50px
● padding:25px;
o all four paddings are 25px
CSS Pseudo-classes
94
The syntax of pseudo-classes:
21
selector:pseudo-class {property:value}
CSS classes can also be used with pseudo-classes:
59
selector.class:pseudo-class {property:value}
Anchor Pseudo-classes
07
Links can be displayed in different ways in a CSS-supporting browser:
80
a:link {color:#FF0000} /* unvisited link */
a:visited {color:#00FF00} /* visited link */
a:hover {color:#FF00FF} /* mouse over link */
a:active {color:#0000FF} /* selected link */
.in
Note: a:hover MUST come after a:link and a:visited in the CSS definition
in order to be effective!!
ys
Note: a:active MUST come after a:hover in the CSS definition in order to
be effective!!
ra
ar
a.red:visited {color:#FF0000}
If the link in the example above has been visited, it will be displayed
in red.
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Match the first <p> element
In the following example, the selector matches any <p> element that is
the first child of any element:
Example
<html>
<head>
<style type="text/css">
p:first-child
94
{
color:blue
}
21
</style>
</head>
59
<body>
<p>I am a strong man.</p>
07
<p>I am a strong man.</p>
</body>
</html>
80
Match the first <i> element in all <p> elements
.in
In the following example, the selector matches the first <i> element in
all <p> elements:
ys
Example
ra
<html>
<head>
ar
<style type="text/css">
p > i:first-child
ith
{
font-weight:bold
w
}
</style>
de
</head>
<body>
co
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Example
<html>
<head>
<style type="text/css">
p:first-child i
{
color:blue
}
</style>
</head>
94
<body>
<p>I am a <i>strong</i> man. I am a <i>strong</i> man.</p>
21
<p>I am a <i>strong</i> man. I am a <i>strong</i> man.</p>
</body>
</html>
59
CSS - The :lang Pseudo-class
07
The :lang pseudo-class allows you to define special rules for different
languages. In the example below, the :lang class defines the type of
80
quotation marks for q elements with a lang attribute with a value of
"no":
<html> .in
<head>
ys
<style type="text/css">
q:lang(no)
ra
{
quotes:"~" "~"
ar
}
</style>
ith
</head>
<body>
w
Some text.</p>
</body>
co
</html>
CSS Pseudo-elements
CSS pseudo-elements are used to add special effects to some selectors.
Syntax
selector:pseudo-element {property:value}
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
CSS classes can also be used with pseudo-elements:
selector.class:pseudo-element {property:value}
p:first-line {color:#0000ff;font-variant:small-caps}
94
<p>Some text that ends up on two or more lines</p>
21
The output could be something like this:
59
up on two or more lines
In the example above the browser displays the first line formatted
07
according to the "first-line" pseudo element. Where the browser breaks
the line depends on the size of the browser window.
80
Note: The "first-line" pseudo-element can only be used with block-level
elements.
.in
Note: The following properties apply to the "first-line" pseudo-element:;
● font properties
ys
● color properties
● background properties
ra
● word-spacing
● letter-spacing
ar
● text-decoration
● vertical-align
ith
● text-transform
● line-height
● clear
w
de
p:first-letter {color:#ff0000;font-size:xx-large}
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
Note: The "first-letter" pseudo-element can only be used with block-level
elements.
● font properties
● color properties
● background properties
● margin properties
● padding properties
●
94
border properties
● text-decoration
● vertical-align (only if "float" is "none")
21
● text-transform
● line-height
● float
59
● clear
07
Pseudo-elements and CSS Classes
80
Pseudo-elements can be combined with CSS classes:
p.article:first-letter {color:#ff0000}
Multiple Pseudo-elements
ar
p:first-letter {color:#ff0000;font-size:xx-large}
p:first-line {color:#0000ff}
w
he first
words of an
article...
In the example above the first letter of the paragraph will be red with a
font size of 24pt. The rest of the first line would be blue while the
rest of the paragraph would be the default color.
------------------------------------------------------------------------------------------------------------
CSS
------------------------------------------------------------------------------------------------------------
The style below will play a sound before each occurrence of an <h1>
element:
h1:before
{
content:url(beep.wav)
}
94
CSS - The :after Pseudo-element
21
The ":after" pseudo-element can be used to insert some content after the
59
content of an element.
The style below will play a sound after each occurrence of an <h1>
07
element:
80
h1:after
{
content:url(beep.wav)
}
.in
ys
ra
ar
ith
w
de
co
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
94
21
59
07
80
JAVASCRIPT .in
ys
ra
ar
ith
w
de
co
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
INDEX
Topics Page No
1. What is Javascript? 4
94
3. Where to Implement JavaScript 5
4. Comments in Javascript 7
21
5. Javascript Variables 8
59
6. Javascript Operators
07
6.1. Arithmetic 10
6.2. Assignment 10
6.3. Comparison 11
80
6.4. Logical 12
6.5. Conditional 12
7. Conditional Statement
7.1. If statement
.in 12
13
7.2. If ………Else statement 13
ys
7.3. If ………Else if Else statement 14
7.4. Switch Case statement 15
ra
ar
8. Pop Up Box
8.1. Alert Box 16
ith
9. Javascript Functions 18
de
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
11.4. onMouseover and onMouseout 24
94
21
59
07
80
.in
ys
ra
ar
ith
w
de
co
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
What is JavaScript?
94
JavaScript was designed to add interactivity to HTML pages
● JavaScript is a scripting language
● A scripting language is a lightweight programming language
21
● JavaScript is usually embedded directly into HTML pages
● JavaScript is an interpreted language (means that scripts execute
without preliminary compilation)
59
● Everyone can use JavaScript without purchasing a license
07
Are Java and JavaScript the same?
80
NO!
perform.
ar
language with a very simple syntax! Almost anyone can put small
de
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
depending on the browser - load another page specifically designed
for that browser
● JavaScript can be used to create cookies - A JavaScript can be
used to store and retrieve information on the visitor's computer
The HTML <script> tag is used to insert a JavaScript into an HTML page.
The example below shows how to use JavaSript to write text on a web page:
Example
94
<html>
<body>
<script type="text/javascript">
21
document.write("Hello World!");
</script>
</body>
59
</html>
07
Where To Implement JavaScript
80
JavaScripts in the body section will be executed WHILE the page loads.
JavaScripts in the head section will be executed when CALLED.
execute a script when a page loads, other times when a user triggers an
event.
ar
Scripts in <head>
ith
If you place a script in the head section, you will ensure that the
script is loaded before anyone uses it.
co
Example
<html>
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event");
}
</script>
</head>
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
<body onload="message()">
</body>
</html>
Scripts in <body>
Scripts to be executed when the page loads go in the body section.
94
Example
21
<html>
<head>
59
</head>
<body>
07
<script type="text/javascript">
document.write("This message is written by JavaScript");
</script>
80
</body>
</html>
<html>
ar
<head>
<script type="text/javascript">
ith
....
</script>
</head>
w
<body>
<script type="text/javascript">
de
....
</script>
</body>
co
If you want to run the same JavaScript on several pages, without having
to write the same script on every page, you can write a JavaScript in an
external file.
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
To use the external script, point to the .js file in the "src" attribute
of the <script> tag:
Example
<html>
<head>
<script type="text/javascript" src="xxx.js"></script>
</head>
<body>
</body>
</html>
94
21
Comments In Javascript
59
JavaScript comments can be used to make the code more readable.
07
Comments can be added to explain the JavaScript, or to make the code more
readable.
80
Single line comments start with //
The following example uses single line comments to explain the code:
.in
Example
ys
<script type="text/javascript">
ra
// Write a heading
document.write("<h1>This is a heading</h1>");
// Write two paragraphs:
ar
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
ith
</script>
w
de
The following example uses a multi line comment to explain the code:
Example
<script type="text/javascript">
/*
The code below will write
one heading and two paragraphs
*/
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
</script>
In the following example the comment is used to prevent the execution of a single code
line (can be suitable for debugging):
94
Example
<script type="text/javascript">
21
//document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
document.write("<p>This is another paragraph.</p>");
59
</script>
07
In the following example the comment is used to prevent the execution of
a code block (can be suitable for debugging):
80
Example
<script type="text/javascript">
/*
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
.in
ys
document.write("<p>This is another paragraph.</p>");
*/
</script>
ra
ar
In the following example the comment is placed at the end of a code line:
w
Example
de
<script type="text/javascript">
document.write("Hello"); // Write "Hello"
document.write(" Dolly!"); // Write " Dolly!"
co
</script>
JavaScript Variables
Variables are "containers" for storing information.
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
x=5, y=6, z=x+y
These letters are called variables, and variables can be used to hold
values (x=5) or expressions (z=x+y).
JavaScript Variables
94
As with algebra, JavaScript variables are used to hold values or
expressions.
21
A variable can have a short name, like x, or a more descriptive name,
like carname.
59
Rules for JavaScript variable names:
07
● Variable names are case sensitive (y and Y are two different
variables)
80
● Variable names must begin with a letter or the underscore character
var x;
var carname;
co
After the declaration shown above, the variables are empty (they have no
values yet).
However, you can also assign values to the variables when you declare
them:
var x=5;
var carname="Volvo";
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
After the execution of the statements above, the variable x will hold the
value 5, and carnamewill hold the value Volvo.
If you assign values to variables that have not yet been declared, the
variables will automatically be declared.
94
These statements:
21
x=5;
carname="Volvo";
59
have the same effect as:
var x=5;
07
var carname="Volvo";
80
Redeclaring JavaScript Variables
have the value of 5. The value of x is not reset (or cleared) when you
redeclare it.
ar
JavaScript Operators
ith
Arithmetic Operators
w
and/or values.
Given that y=5, the table below explains the arithmetic operators:
co
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
-- Decrement x=--y x=4
JavaScript Assignment Operators
Given that x=10 and y=5, the table below explains the assignment
operators:
94
+= x+=y x=x+y x=15
-= x-=y x=x-y x=5
21
*= x*=y x=x*y x=50
/= x/=y x=x/y x=2
59
%= x%=y x=x%y x=0
The + Operator Used on Strings
07
The + operator can also be used to add string variables or text values
together.
80
To add two or more string variables together, use the + operator.
txt1="What a very";
txt2="nice day";
.in
txt3=txt1+txt2;
ys
After the execution of the statements above, the variable txt3 contains
"What a verynice day".
ra
To add a space between the two strings, insert a space into one of the
ar
strings:
ith
txt3=txt1+txt2;
or insert a space into the expression:
de
txt1="What a very";
co
txt2="nice day";
txt3=txt1+" "+txt2;
After the execution of the statements above, the variable txt3 contains:
The rule is: If you add a number and a string, the result will be a
string!
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
Example
x=5+5;
document.write(x);
x="5"+"5";
document.write(x);
x=5+"5";
document.write(x);
x="5"+5;
document.write(x);
94
21
JavaScript Comparison and Logical Operators
Comparison and Logical operators are used to test for true or false.
59
Comparison Operators
07
Comparison operators are used in logical statements to determine equality
or difference between variables or values.
80
Given that x=5, the table below explains the comparison operators:
Operator
==
Description
is equal to
.in
Example
x==8 is false
ys
=== is exactly equal to (value and type) x===5 is true
x==="5" is false
ra
Comparison operators can be used in conditional statements to compare values and take
action depending on the result:
co
Given that x=6 and y=3, the table below explains the logical operators:
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
|| or (x==5 || y==5) is false
! not !(x==y) is true
Conditional Operator
Syntax
variablename=(condition)?value1:value2
94
Example
greeting=(visitor=="PRES")?"Dear President ":"Dear ";
If the variable visitor has the value of "PRES", then the
21
variable greeting will be assigned the value "Dear President " else it
will be assigned "Dear".
59
Conditional Statements
07
Conditional statements are used to perform different actions based on
different conditions.
80
Very often when you write code, you want to perform different actions for different
decisions. You can use conditional statements in your code to do this.
● switch statement - use this statement to select one of many blocks of code to
be executed
ith
If Statement
w
is true.
co
Syntax
if (condition)
{
code to be executed if condition is true
}
Note that if is written in lowercase letters. Using uppercase letters
(IF) will generate a JavaScript error!
Example
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
<script type="text/javascript">
//Write a "Good morning" greeting if
//the time is less than 10
if (time<10)
{
document.write("<b>Good morning</b>");
}
</script>
94
Notice that there is no ..else.. in this syntax. You tell
21
the browser to execute some code only if the specified
condition is true.
59
If...else Statement
07
Use the if....else statement to execute some code if a condition is true
and another code if the condition is not true.
80
Syntax
if (condition)
{
code to be executed if condition is true
}
.in
else
ys
{
code to be executed if condition is not true
ra
}
ar
Example
ith
<script type="text/javascript">
//If the time is less than 10, you will get a "Good morning" greeting.
//Otherwise you will get a "Good day" greeting.
w
{
document.write("Good morning!");
}
else
{
document.write("Good day!");
}
</script>
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
Syntax
if (condition1)
{
code to be executed if condition1 is true
}
else if (condition2)
{
code to be executed if condition2 is true
}
94
else
{
code to be executed if condition1 and condition2 are not true
21
}
59
Example
<script type="text/javascript">
07
var d = new Date()
var time = d.getHours()
if (time<10)
80
{
document.write("<b>Good morning</b>");
}
else if (time>10 && time<16)
{
document.write("<b>Good day</b>");
}
.in
ys
else
{
document.write("<b>Hello World!</b>");
ra
}
</script>
ar
ith
Use the switch statement to select one of many blocks of code to be executed.
co
Syntax
switch(n)
{
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
This is how it works: First we have a single expression n (most often a
variable), that is evaluated once. The value of the expression is then
compared with the values for each case in the structure. If there is a
match, the block of code associated with that case is executed.
Usebreak to prevent the code from running into the next case
automatically.
Example
<script type="text/javascript">
//You will receive a different greeting based
//on what day it is. Note that Sunday=0,
94
//Monday=1, Tuesday=2, etc.
21
theDay=d.getDay();
switch (theDay)
{
59
case 5:
document.write("Finally Friday");
break;
07
case 6:
document.write("Super Saturday");
break;
80
case 0:
document.write("Sleepy Sunday");
break;
default:
}
document.write("I'm looking forward to this weekend!"); .in
</script>
ys
ra
JavaScript has three kind of popup boxes: Alert box, Confirm box, and
Prompt box.
ith
Alert Box
w
An alert box is often used if you want to make sure information comes
de
When an alert box pops up, the user will have to click "OK" to proceed.
co
Syntax
alert("sometext");
Example
<html>
<head>
<script type="text/javascript">
function show_alert()
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
{
alert("I am an alert box!");
}
</script>
</head>
<body>
</body>
</html>
94
Confirm Box
21
A confirm box is often used if you want the user to verify or accept
59
something.
When a confirm box pops up, the user will have to click either "OK" or
07
"Cancel" to proceed.
80
If the user clicks "OK", the box returns true. If the user clicks
"Cancel", the box returns false.
Syntax
confirm("sometext");
.in
ys
Prompt Box
ra
A prompt box is often used if you want the user to input a value before
entering a page.
ar
ith
When a prompt box pops up, the user will have to click either "OK" or
"Cancel" to proceed after entering an input value.
w
If the user clicks "OK" the box returns the input value. If the user
de
Syntax
co
prompt("sometext","defaultvalue");
Example
<html>
<head>
<script type="text/javascript">
function show_prompt()
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
{
var name=prompt("Please enter your name","Harry Potter");
if (name!=null && name!="")
{
document.write("Hello " + name + "! How are you today?");
}
}
</script>
</head>
<body>
94
</body>
</html>
21
59
JavaScript Functions
07
A function will be executed by an event or by a call to the function.
80
To keep the browser from executing a script when the page loads, you can
put your script into a function.
Functions can be defined both in the <head> and in the <body> section of
ar
<head> section.
Syntax
function functionname(var1,var2,...,varX)
{
co
some code
}
The parameters var1, var2, etc. are variables or values passed into the
function. The { and the } defines the start and end of the function.
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
JavaScript error occurs! Also note that you must call a function with the
exact same capitals as in the function name.
Example
<html>
<head>
<script type="text/javascript">
function displaymessage()
{
94
alert("Hello World!");
}
</script>
21
</head>
<body>
59
<form>
<input type="button" value="Click me!" onclick="displaymessage()" />
</form>
07
</body>
</html>
80
If the line: alert("Hello world!!") in the example above had not been put
within a function, it would have been executed as soon as the line was
loaded. Now, the script is not executed before a user hits the input
button. The function displaymessage() will be executed if the input
button is clicked.
.in
ys
The return Statement
ra
The return statement is used to specify the value that is returned from
the function.
ar
So, functions that are going to return a value must use the return
ith
statement.
w
The example below returns the product of two numbers (a and b):
de
Example
co
<html>
<head>
<script type="text/javascript">
function product(a,b)
{
return a*b;
}
</script>
</head>
<body>
<script type="text/javascript">
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
document.write(product(4,3));
</script>
</body>
</html>
94
local variables with the same name in different functions, because each
is recognized only by the function in which it is declared.
21
If you declare a variable outside a function, all the functions on your
page can access it. The lifetime of these variables starts when they are
59
declared, and ends when the page is closed.
07
JavaScript Loop
Loops execute a block of code a specified number of times, or while a
80
specified condition is true.
Often when you write code, you want the same block of code to run over
.in
and over again in a row. Instead of adding several almost equal lines in
a script we can use loops to perform a task like this.
ys
In JavaScript, there are two different kind of loops:
ra
is true
ith
The for loop is used when you know in advance how many times the script
should run.
de
Syntax
co
for (var=startvalue;var<=endvalue;var=var+increment)
{
code to be executed
}
Example
The example below defines a loop that starts with i=0. The loop will
continue to run as long as iis less than, or equal to 5. i will increase
by 1 each time the loop runs.
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
Note: The increment parameter could also be negative, and the <= could be
any comparing statement.
Example
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++)
{
document.write("The number is " + i);
94
document.write("<br />");
}
</script>
21
</body>
</html>
59
JavaScript While Loop
07
Loops execute a block of code a specified number of times, or while a
specified condition is true.
80
The while Loop
.in
The while loop loops through a block of code while a specified condition
is true.
ys
Syntax
ra
while (var<=endvalue)
{
code to be executed
ar
}
Note: The <= could be any comparing statement.
ith
Example
w
The example below defines a loop that starts with i=0. The loop will
de
continue to run as long as iis less than, or equal to 5. i will increase
by 1 each time the loop runs:
co
Example
<html>
<body>
<script type="text/javascript">
var i=0;
while (i<=5)
{
document.write("The number is " + i);
document.write("<br />");
i++;
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
}
</script>
</body>
</html>
The do...while loop is a variant of the while loop. This loop will
94
execute the block of code ONCE, and then it will repeat the loop as long
as the specified condition is true.
21
Syntax
do
59
{
code to be executed
}
07
while (var<=endvalue);
Example
80
The example below uses a do...while loop. The do...while loop will always
be executed at least once, even if the condition is false, because the
statements are executed before the condition is tested:
.in
Example
ys
<html>
ra
<body>
<script type="text/javascript">
var i=0;
ar
do
{
ith
}
while (i<=5);
de
</script>
</body>
</html>
co
The break statement will break the loop and continue executing the code
that follows after the loop (if any).
Example
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=10;i++)
{
if (i==3)
{
break;
}
document.write("The number is " + i);
document.write("<br />");
}
94
</script>
</body>
</html>
21
The continue Statement
59
The continue statement will break the current loop and continue with the
07
next value.
80
Example
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
.in
ys
{
if (i==3)
{
ra
continue;
}
ar
}
</script>
</body>
w
</html>
de
Syntax
for (variable in object)
{
code to be executed
}
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
Note: The code in the body of the for...in loop is executed once for each
element/property.
Example
Example
94
<html>
<body>
21
<script type="text/javascript">
var x;
59
var mycars = new Array();
mycars[0] = "Saab";
mycars[1] = "Volvo";
07
mycars[2] = "BMW";
for (x in mycars)
80
{
document.write(mycars[x] + "<br />");
}
</script>
</body>
.in
</html>
ys
ra
JavaScript Events
ar
Every element on a web page has certain events which can trigger a
de
JavaScript. For example, we can use the onClick event of a button element
to indicate that a function will run when a user clicks on the button. We
co
Examples of events:
● A mouse click
● A web page or an image loading
● Mousing over a hot spot on the web page
● Selecting an input field in an HTML form
● Submitting an HTML form
● A keystroke
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
Note: Events are normally used in combination with functions, and the
function will not be executed before the event occurs!
The onLoad and onUnload events are triggered when the user enters or
leaves the page.
The onLoad event is often used to check the visitor's browser type and
browser version, and load the proper version of the web page based on the
information.
94
Both the onLoad and onUnload events are also often used to deal with
cookies that should be set when a user enters or leaves a page. For
21
example, you could have a popup asking for the user's name upon his first
arrival to your page. The name is then stored in a cookie. Next time the
59
visitor arrives at your page, you could have another popup saying
something like: "Welcome John Doe!".
07
onFocus,onClick onBlur and onChange
80
The onFocus, onBlur and onChange events are often used in combination
with validation of form fields.
onSubmit
ar
The onSubmit event is used to validate ALL form fields before submitting
it.
ith
function will be called when the user clicks the submit button in the
form. If the field values are not accepted, the submit should be
de
cancelled:
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
<a href="http://www.w3schools.com" onmouseover="alert('An onMouseOver
event');return false"><img src="w3s.gif" alt="W3Schools" /></a>
The backslash (\) is used to insert apostrophes, new lines, quotes, and
other special characters into a text string.
94
Look at the following JavaScript code:
21
document.write(txt);
In JavaScript, a string is started and stopped with either single or
59
double quotes. This means that the string above will be chopped to: We
are the so-called
07
To solve this problem, you must place a backslash (\) before each double
quote in "Viking". This turns each double quote into a string literal:
80
var txt="We are the so-called \"Vikings\" from the north.";
document.write(txt);
.in
JavaScript will now output the proper text string: We are the so-called
"Vikings" from the north.
ys
Here is another example:
ra
Code Outputs
\' single quote
co
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
JavaScript String Object
Examples of use:
The following example uses the length property of the String object to find the length
of a string:
94
var txt="Hello world!";
document.write(txt.length);
21
The code above will result in the following output:
59
12
The following example uses the toUpperCase() method of the String object to
convert a string to uppercase letters:
07
var txt="Hello world!";
80
document.write(txt.toUpperCase());
The code above will result in the following output:
An array is a special variable, which can hold more than one value, at a time.
ar
If you have a list of items (a list of car names, for example), storing the cars in
ith
$cars1="Saab";
de
$cars2="Volvo";
$cars3="BMW";
However, what if you want to loop through the cars and find a specific one? And
co
An array can hold all your variable values under a single name. And you can access
the values by referring to the array name.
Each element in the array has its own ID so that it can be easily accessed.
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
Create an Array
1:
94
var myCars=new Array();
myCars[0]="Saab";
myCars[1]="Volvo";
21
myCars[2]="BMW";
You could also pass an integer argument to control the array's size:
59
var myCars=new Array(3);
myCars[0]="Saab";
07
myCars[1]="Volvo";
myCars[2]="BMW";
80
2:
You can refer to a particular element in an array by referring to the name of the
array and the index number. The index number starts at 0.
ar
document.write(myCars[0]);
w
Saab
Modify Values in an Array
co
To modify a value in an existing array, just add a new value to the array with a
specified index number:
myCars[0]="Opel";
Now, the following code line:
document.write(myCars[0]);
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
will result in the following output:
Opel
It's very easy to time events in JavaScript. The two key methods that are used are:
94
● setTimeout() - executes a code some time in the future
● clearTimeout() - cancels the setTimeout()
21
Note: The setTimeout() and clearTimeout() are both methods of the HTML DOM
59
Window object.
07
Syntax
80
,milliseconds);
var t=setTimeout("javascript statement"
The setTimeout() method returns a value - In the statement above, the value is stored in a variable called
t. If you want to cancel this setTimeout(), you can refer to it using the variable name.
.in
The first parameter of setTimeout() is a string that contains a JavaScript statement. This statement could
be a statement like "alert('5 seconds!')" or a call to a function, like "alertMsg()".
ys
The second parameter indicates how many milliseconds from now you want to execute the first parameter.
ra
Example
ith
When the button is clicked in the example below, an alert box will be displayed after 5 seconds.
w
Example
de
<html>
<head>
<script type="text/javascript">
co
function timedMsg()
{
var t=setTimeout("alert('5 seconds!')",5000);
}
</script>
</head>
<body>
<form>
<input type="button" value="Display timed alertbox!"
onClick="timedMsg()" />
</form>
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
</body>
</html>
To get a timer to work in an infinite loop, we must write a function that calls itself. In the example below,
when the button is clicked, the input field will start to count (for ever), starting at 0:
Example
94
<html>
<head>
<script type="text/javascript">
21
var c=0
var t
function timedCount()
59
{
document.getElementById('txt').value=c;
c=c+1;
07
t=setTimeout("timedCount()",1000);
}
</script>
80
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="timedCount()" />
<input type="text" id="txt" />
.in
</form>
ys
</body>
</html>
ra
ar
Syntax
clearTimeout(setTimeout_variable)
w
Example
de
The example below is the same as the "Infinite Loop" example above. The only difference is that we have
now added a "Stop Count!" button that stops the timer:
co
Example
<html>
<head>
<script type="text/javascript">
var c=0
var t
function timedCount()
{
document.getElementById('txt').value=c;
------------------------------------------------------------------------------------------------------------
JAVASCRIPT
------------------------------------------------------------------------------------------------------------
c=c+1;
t=setTimeout("timedCount()",1000);
}
function stopCount()
{
clearTimeout(t);
}
</script>
</head>
<body>
<form>
94
<input type="button" value="Start count!" onClick="timedCount()" />
<input type="text" id="txt" />
<input type="button" value="Stop count!" onClick="stopCount()" />
21
</form>
</body>
59
</html>
07
JavaScript Form Validation
80
JavaScript can be used to validate data in HTML forms before sending off the content to a server.
●
●
has the user left required fields empty?
has the user entered a valid e-mail address?
.in
● has the user entered a valid date?
ys
● has the user entered text in a numeric field?
ra
var field_val=document.getElementById(‘fieldid’).value;
ith
if(field_val==””)
{
w
}
else
co
{
alert(“The Field is not Empty”);
}
------------------------------------------------------------------------------------------------------------
freelance_Project available to buy contact on 8007592194
SR.NOProject NAME Technology
1 Online E-Learning Platform Hub React+Springboot+MySql
94
2 PG Mates / RoomSharing / Flat Mates React+Springboot+MySql
21
3 Tour and Travel management System React+Springboot+MySql
59
5 HomeRental Booking System React+Springboot+MySql
07
6 Event Management System React+Springboot+MySql
80
8 Agriculture web Project React+Springboot+MySql
9 AirLine Reservation System / Flight booking System React+Springboot+MySql
.in
10 E-commerce web Project React+Springboot+MySql
ys
11 Hospital Management System React+Springboot+MySql
ra
12 E-RTO Driving licence portal React+Springboot+MySql
13 Transpotation Services portal
ar
React+Springboot+MySql
14 Courier Services Portal / Courier Management System React+Springboot+MySql
ith
15 Online Food Delivery Portal React+Springboot+MySql
w
16 Muncipal Corporation Management React+Springboot+MySql
17 Gym Management System de React+Springboot+MySql
co
18 Bike/Car ental System Portal React+Springboot+MySql
19 CharityDonation web project React+Springboot+MySql
20 Movie Booking System React+Springboot+MySql
freelance_Project available to buy contact on 8007592194
21 Job Portal web project React+Springboot+MySql
22 LIC Insurance Portal React+Springboot+MySql
23 Employee Management System React+Springboot+MySql
94
24 Payroll Management System React+Springboot+MySql
25 RealEstate Property Project React+Springboot+MySql
21
26 Marriage Hall Booking Project React+Springboot+MySql
27 Online Student Management portal React+Springboot+MySql
59
28 Resturant management System React+Springboot+MySql
29 Solar Management Project React+Springboot+MySql
07
30 OneStepService LinkLabourContractor React+Springboot+MySql
31 Vehical Service Center Portal React+Springboot+MySql
80
32 E-wallet Banking Project React+Springboot+MySql
33 Blogg Application Project React+Springboot+MySql
34 Car Parking booking Project React+Springboot+MySql
.in
35 OLA Cab Booking Portal React+Springboot+MySql
36 Society management Portal React+Springboot+MySql
ys
37 E-College Portal React+Springboot+MySql
38 FoodWaste Management Donate System React+Springboot+MySql
ra
39 Sports Ground Booking React+Springboot+MySql
ar
40 BloodBank mangement System React+Springboot+MySql
41 Bus Tickit Booking Project React+Springboot+MySql
ith
42 Fruite Delivery Project React+Springboot+MySql
43 Woodworks Bed Shop React+Springboot+MySql
w
44 Online Dairy Product sell Project React+Springboot+MySql
45
46
Online E-Pharma medicine sell Project
FarmerMarketplace Web Project
de
React+Springboot+MySql
React+Springboot+MySql
co
47 Online Cloth Store Project React+Springboot+MySql
48 React+Springboot+MySql
49 React+Springboot+MySql
50 React+Springboot+MySql
https://www.youtube.com/@codewitharrays
94
https://www.instagram.com/codewitharrays/
21
59
07
https://t.me/codewitharrays Group Link: https://t.me/cceesept2023
80
.in
+91 8007592194 +91 9284926333
ys
ra
ar
ith
[email protected]
w
de
co
https://codewitharrays.in/project