Uploaded by Herbert Loïc

Lecture-1===HTML

advertisement
FACULTY OF COMPUTING AND INFORMATION SCIENCES
CLASS: YEAR III ISM(Nyanza CAMPUS)
MODULE TITLE: WEB TECHNOLOGY
LECTURER: Mr. Frodouard Minani
Telephone: +250782149182
Email: frodominani@gmail.com
1
Brief Summary
▪ The major success of academic institution or busing organization nowadays depends
on the attention paid on the visibility;
Interactive Website is driving force for
advertisements, managing user generated content and quick data processing and
sharing.
▪ This course discusses the technologies used to put content on the web, formatting
web content and making website dynamic by improving navigation and attracting
and retaining users on websites by using look and feel concepts.
Course Expectation
Up on completion of this course, students will be able:
➢ To understand and use the JavaScript, CSS and PHP/MySql to develop dynamic and
interactive web sites
➢ To manage content and web documents on Local Server Side
➢ To Manage Hosted Web Sites on Online Web Server
2
Table of Content
1. History and overview of the Web
2. Static Web:
a. HyperText Markup Language (HTML)
b. JavaScript Content:
1.
2.
3.
4.
5.
6.
Introduction
Control Statements in JavaScript
Functions in JavaScript
Arrays in JavaScript
Form Validation
Events Handling in JavaScript
c. CSS Content
1. Introduction
2. CSS Selectors
3. Embedding CSS in HTML
Document(inline, internal and
external styling)
4. CSS Properties
5. CSS Layout (Page Layout, Form,
Table Layouts)
6. CSS and JavaScript Menus
3. Dynamic Web (Interactive Websites) :PHP/MySql
1. Basics of PHP for Server Side Programming
2. Introduction PHP/MySql and User Interaction
3. Advanced PHP Programming (Use of Class and Object)
4. Connecting PHP to MySql Database
5. MySql Database Manipulation using PHP
6. Combining HTML/CSS/JavaScript and PHP/MySql to
improve Web Page Navigation
3
History and Overview of the Web
Overview of WWW
4
➢Although many people use the terms
➢Each electronic document on the
World
Internet
Web is called a Web page, which can
interchangeably, the World Wide Web
contain text, graphics, animation,
actually is a service of the Internet.
audio, and video.
Wide
Web
and
➢While the Internet was developed in
the late 1960s, the World Wide Web
emerged in the early 1990s.
➢The World Wide Web (WWW), or
Web, consists of a worldwide collection
of electronic documents and services,
distributed across the Internet and
linked together by hypertext links.
➢Some Web pages are static (fixed);
others are dynamic (changing).
5
➢A Web site is a collection of related Web
pages
and
associated
items,
such
as
Evolution of WWW
documents and pictures, stored on a Web
server.
➢World
➢A Web server is a computer that delivers
created by Timothy Berners
requested Web pages to your computer.
Lee in 1989 at CERN in Geneva
Wide
Web
was
➢The same Web server can store multiple Web
sites.
Evolution of WWW
6
Browsing the Web
➢A Web browser, or browser, is application
➢The more widely used Web
software that allows users to access and view
browsers for personal computers
Web pages or access Web 2.0 programs.
are
➢To browse the Web, you need a computer or
Opera, Safari, and Google Chrome.
mobile device that is connected to the
Internet and has a Web browser.
Internet
Explorer,
Firefox,
➢The browser retrieves and displays
a starting Web page, sometimes
called the browser’s home page
✓For a computer or mobile device to display a Web page, the page
must be downloaded.
✓Downloading is the process of a computer or device receiving
information, such as a Web page, from a server on the Internet
7
➢The organization that assigns and controls
top-level domains is the Internet Corporation
for Assigned Names and Numbers (ICANN
pronounced EYE-can)
➢The domain name system (DNS) is the
method that the Internet uses to store
domain names and their corresponding IP
addresses.
➢When domain name is specified, a DNS
server translates the domain name to its
associated IP address so that data and
information can be routed to the correct
computer.
➢A DNS server is an Internet server that
usually is associated with an Internet access
provider.
Examples of Generic Top-Level Domains
10
Web Addresses
➢A Web page has a unique address, called a URL (Uniform Resource
Locator) or Web address
11
Static & Dynamic Websites
➢We consider there are two
types of web sites: static web
➢Dynamic web sites: more complex,
sites and dynamic web sites.
they use other languages in addition
➢Static web sites: web sites
to (X) HTML and CSS, such as PHP and
that are performed solely for the
MySQL.
languages (X) HTML and CSS.
➢The content of these web sites is
➢They work very well but their
called "dynamic" because it can
contents cannot be updated
change without the intervention of
automatically: it requires that
the webmaster!
the web site owner (webmaster)
➢Most web sites you visit today are
modifies the source code for
dynamic web sites.
adding new content
12
How does a web site work?
For a static web site
➢When the web site is static, the
pattern is very simple.
➢This happens in two stages:
* The client asks the server to
see a web page.
* The server responds by sending
For a dynamic web site with PHP and MySQL
➢When the web site is dynamic, there is
an intermediate step: the page is
generated.
* The client asks the server to see a web
page.
* The server prepares the page
specifically for the client’s request.
* The server sends the page it has
generated.
the requested page.
In the case of a static web site, the server stores web
pages and sends back the entire web page
▪ The web page is generated each time a client (web
browser) demands it.
▪ This is precisely what
makes dynamic web sites alive: the content of a page can
change from moment to moment.
13
Programming languages for web sites.
•CSS is the language formatting of
➢For a static web site: XHTML
web sites.
which is the language at the base of
•While XHTML is used to write the
web sites. It is very similar to HTML
contents of your web pages and
but imposes some rules a little
the structure, the CSS handles the
stricter and CSS.
formatting and layout.
•This CSS is that we choose the
➢An example of XHTML code:
<p>This is a snapshot of a
<em>paragraph</em> of text!</p>
•For a dynamic web site: We add PHP
and MySQL
particular color, size, menus and
much more.
Here is a CSS code:
div.banner {
text-align: center;
font-weight: bold;
font-size: 120%;
}
14
What programs do we need?
With a static web site
•A text editor: such as Notepad shipped with Windows only, although it is
Recommended to use a bit more advanced tool like Notepad + +.
•A web browser: it can test the web page, eg : Mozilla Firefox, Internet
Explorer, Google Chrome, Opera, Safari etc
•A web server (such as Apache): This is responsible for hosting and
issuing web pages to visitors. However, Apache only handles static web
sites (it can only handle HTML pages).
15
Introduction to HTML
16
➢HTML stands for Hyper Text Markup Language, which is the most
widely used language on Web to develop web pages.
➢HTML was created by Berners-Lee in late 1991 but "HTML 2.0" was the
first standard HTML specification which was published in 1995.
➢ HTML 4.01 was a major version of HTML and it was published in late
1999.
➢Though HTML 4.01 version is widely used but currently we are having
HTML-5 version which is an extension to HTML 4.01, and this version
was published in 2012.
17
▪ A markup language is used to control the presentation of data, like
"represent these usernames as a bullet list or as a table“ (It is used to
create structure.
▪ Example: HTML, XML, XHTML,XSLT and more………
▪ A scripting language is used to mediate between programs in order to
generate data( it is like a programming language but it is interpreted
before compiled).
▪ Example: PHP,JAVASCRIPT, JSP,ASP,PYTHON,PERL and more……..
19
▪ A programming language is used to transform data.
▪
It does so by creating CPU instructions that rewrite the input data into
the output; hopefully, the desired output. (It is a set of instructions to
the computer to perform. It is compiled and interpreted before it gets
executed)
▪ Examples of transforming data is to compute a sum out of a number
of addends
▪ Example: C,C++,CORE JAVA,FORTAIN,C# and more…..
20
Structure of a Simple HTML Document
21
HTML Tags
➢ HTML tags are element
names surrounded by angle
brackets:
<tagname>content
goes
here...</tagname>
➢
HTML tags normally come in
pairs like <p> and </p>
➢
The first tag in a pair is the start
tag, the second tag is the end tag
➢
The end tag is written like the
start tag, but with a forward
slash inserted before the tag
name.
22
HTML Page Structure
o Only the content inside the <body> section (the white area above) is displayed in23a
browser.
HTML Basic
HTML Documents
Example
▪ All HTML documents must start
with
a
document
type
declaration: <!DOCTYPE html>.
▪ The HTML document itself begins
with <html> and ends with </html>.
▪ The visible part of the HTML
document
is
between <body> and </body>.
24
HTML Headings
▪ HTML headings are defined with the <h1> to <h6> tags. <h1>
defines the most important heading. <h6> defines the least important
heading:
25
HTML Paragraphs
▪ HTML paragraphs are defined with the <p> tag
HTML Links
▪ HTML links are defined with the <a> tag
▪ The link's destination is specified in the href attribute.
26
HTML Images
▪ HTML images are defined with the <img> tag.
▪ The source file (src), alternative text (alt), width, and height are provided as
attributes.
27
HTML Elements
▪ An HTML element is defined by a starting tag.
▪
If the element contains other content, it ends with a closing tag, where the
element name is preceded by a forward slash as shown below with few tags.
28
▪ Here <p>....</p> is an HTML element, <h1>...</h1>
is another HTML element.
▪ There are some HTML elements which don't need to
be closed, such as <img.../>, <hr /> and <br />
elements.
▪ These are known as void elements.
29
HTML Tag vs. Element
▪ An HTML element is defined by a starting tag.
▪ If the element contains other content, it ends with a closing tag.
o For example, <p> is starting tag of a paragraph and </p> is
closing
tag
of
the
same
paragraph
but
<p>This
is
paragraph</p> is a paragraph element.
Nested HTML Elements
<!DOCTYPE html> <html>
<head> <title>Nested Elements Example</title>
</head><body>
<h1>This is <i>italic</i> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
</body> </html>
30
HTML – ATTRIBUTES
▪ An attribute is used to define the characteristics of an HTML element and is
placed inside the element's opening tag.
▪
All attributes are made up of two parts: a name and a value.
➢ The name is the property you want to set.
o For example, the paragraph <p> element in the example carries an
attribute whose name is align, which you can use to indicate the alignment
of paragraph on the page.
➢ The value is what you want the value of the property to be set and
always put within quotations.
o The below example shows three possible values of align attribute: left,
center and right.
31
Example:
32
Some examples of Attributes
▪ The href Attribute
HTML links are defined with the <a> tag. The link address is specified in the
href attribute:
<a href="https://www.w3schools.com">This is a
link</a>
▪ Size Attributes
HTML images are defined with the <img> tag.
The filename of the source (src), and the size of the image (width and
height) are all provided as attributes:
<img src="w3schools.jpg" width="104" height="142">
33
The alt Attribute
▪ The alt attribute specifies an alternative text to be used, when an
image cannot be displayed.
Example
<img src="w3schools.jpg"
alt="W3Schools.com" width="104"
height="142">
34
Generic Attributes
▪ Here's a table of some other attributes that are readily usable with many of
the HTML tags.
35
HTML – FORMATTING
▪ Bold Text
Anything that appears within <b>...</b>
element, is displayed in bold as shown below
Example
<!DOCTYPE html>
<html>
<head>
<title>Bold Text Example</title> </head>
<body>
<p>The following word uses a <b>bold</b>
typeface.</p>
</body>
</html>
36
▪ Italic Text
Anything that appears within <i>...</i> element is displayed in italicized
as shown below.
Example
<!DOCTYPE html>
<html>
<head>
<title>Italic Text Example</title>
</head>
<body>
<p>The following word uses an
<i>italicized</i> typeface.</p>
</body></html>
37
▪ Underlined Text
Anything that appears within <u>...</u> element, is displayed with
underline as shown below
Example
<!DOCTYPE html>
<html>
<head>
<title>Underlined Text
Example</title>
</head>
<body>
<p>The following word uses an
<u>underlined</u> typeface.</p>
</body>
</html>
38
▪ Strike Text
Anything that appears within <strike>...</strike> element is displayed with
strikethrough, which is a thin line through the text as shown below:
Example
<!DOCTYPE html>
<html>
<head>
<title>Strike Text Example</title>
</head>
<body>
<p>The following word uses a
<strike>strikethrough</strike>
typeface.</p>
</body>
</html>
39
Grouping Content in HTML
▪ The <div> and <span> elements allow you to group together several
elements to create sections or subsections of a page.
▪ For example, you might want to put all of the footnotes on a page within
a <div> element to indicate that all of the elements within that <div>
element relate to the footnotes.
▪ You might then attach a style to this <div> element so that they appear
using a special set of style rules.
40
<!DOCTYPE html>
<html>
<head>
<title>Div Tag Example</title>
</head>
<body>
<div id = "menu" align = "middle" >
<a href = "/index.htm">HOME</a> |
<a href = "/about/contact_us.htm">CONTACT</a> |
<a href = "/about/index.htm">ABOUT</a>
</div>
<div id = "content" align = "left" bgcolor = "white">
<h5>Content Articles</h5>
<p>Actual content goes here.....</p>
</div>
</body>
</html>
41
HTML – IMAGES
▪ In HTML, images are defined with the <img> tag.
▪ The <img> tag is empty, it contains attributes only, and does
not have a closing tag.
▪ The src attribute specifies the URL (web address) of the
image:
<!DOCTYPE html> <html>
<body>
<h2>Spectacular Mountain</h2>
<img src="pic_mountain.jpg"
alt="Mountain
View"style="width:304px;height:228px;">
</body>
</html>
42
The alt Attribute
▪ The alt attribute provides an alternate text for an image, if the user for some
reason cannot view it (because of slow connection, an error in the src
attribute, or if the user uses a screen reader).
▪ If a browser cannot find an image, it will display the value of the alt attribute:
Example
<img src="wrongname.gif" alt="HTML5 Icon"
style="width:128px;height:128px;">
Image Size - Width and Height
▪ You can use the style attribute to specify the width and height of an
image.
▪ The values are specified in pixels (use px after the value):
43
▪ Alternatively, you can use the width and height attributes.
▪ Here, the values are specified in pixels by default:
Example
<img src="html5.gif" alt="HTML5 Icon" width="128"
height="128">
Width and Height, or Style?
▪ Both the width, height, and style attributes are valid in HTML5.
▪ However, we suggest using the style attribute.
▪ It prevents internal or external styles sheets from changing the original
size of images:
44
<!DOCTYPE html> <html> <head> <style>
img {
width:100%;
}
</style>
</head> <body> <img src="html5.gif" alt="HTML5
Icon" style="width:128px;height:128px;"> <img
src="html5.gif" alt="HTML5 Icon" width="128"
height="128">
</body> </html>
45
Using an Image as a Link
• To use an image as a link, simply nest the <img> tag inside the
<a> tag:
Example
<a href="default.asp"> <img
src="smiley.gif" alt="HTML
tutorial"style="width:42px;height:42px;bo
rder:0;"> </a>
46
Maps
➢ Use the <map> tag to define an image-map.
➢ An image-map is an image with clickable areas.
➢ The name attribute of the <map> tag is associated with
the
<img>'s
usemap
attribute
and
creates
a
relationship between the image and the map.
➢ The <map> tag contains a number of <area> tags, that
defines the clickable areas in the image-map:
47
<!DOCTYPE html>
<html>
<body>
<p>Click on the sun or on one of the planets to watch it closer:</p>
<img src="planets.gif" width="145" height="126" alt="Planets"
usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
<area shape="circle" coords="90,58,3" alt="Mercury“
href="mercur.htm">
<area shape="circle" coords="124,58,8" alt="Venus"
href="venus.htm">
</map>
</body>
</html>
48
Background Image
▪ To add a background image on an HTML element, use the CSS
property background-image:
Example
▪ To add a background image on a web page, specify the
background-image property on the BODY element:
<body style="background-image:url('skies.jpg')">
<h2>Background Image</h2> </body>
49
▪ To add a background image on a paragraph, specify the background-image
property on the P element:
<body>
<p
style="background-image:url('skies.jpg')">
</body>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("paper.gif");
background-color: #cccccc;
}
</style>
</head>
<body>
<h1>The background-image Property</h1>
<p>Hello World!</p>
</body>
</html>
...
</p>
50
Background Color
<!DOCTYPE html>
<html>
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
51
HTML Tables
▪ An HTML table is defined with the <table> tag.
▪ Each table row is defined with the <tr> tag.
▪ A table header is defined with the <th> tag.
▪ By default, table headings are bold and centered.
▪ A table data/cell is defined with the <td> tag.
52
<!DOCTYPE html>
<html>
<head>
<title>HTML
Tables</title>
</head> <body>
<table border="1">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
</body>
</html>
Output
▪ The border is an attribute of
<table> tag and it is used to put
a border across all the cells.
▪ If you do not need a border,
then you can use border="0".
53
Table Heading
▪ Table heading can be defined using <th> tag.
▪ This tag will be put to replace <td> tag, which is used to represent
actual data cell.
<!DOCTYPE html>
<html>
<head> <title>HTML Table Header</title>
</head> <body>
<table border="1"> <tr>
<th>Name</th> <th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td></tr> </table> </body>
</html>
Output
54
Cellpadding and Cellspacing Attributes
▪ There are two attributes called cellpadding and cellspacing which you will
use to adjust the white space in your table cells.
▪ The cellspacing attribute defines the width of the border, while
cellpadding represents the distance between cell borders and the content
within a cell.
<!DOCTYPE html>
<html>
<head> <title>HTML Table Header</title>
</head> <body>
<table border="1“cellpadding="5" cellspacing="5">
<tr>
<th>Name</th> <th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr> <tr> <td>Shabbir Hussein</td>
<td>7000</td></tr> </table> </body></html>
Output
55
Colspan and Rowspan Attributes
▪ You will use colspan attribute if you want to merge two or more columns into a
single column.
▪ Similar way you will use rowspan if you want to merge two or more rows.
<!DOCTYPE html>
<html>
<head>
<title>HTML Table
Colspan/Rowspan</title>
</head>
<body>
<table border="1"> <tr><th>Column
1</th>
<th>Column 2</th><th>Column 3</th>
</tr><tr><td rowspan="2">Row 1 Cell
1</td><td>Row 1 Cell 2</td><td>Row 1
Cell 3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2
Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell
1</td></tr></table> </body> </html>
Output
56
Tables Backgrounds
▪ You can set table background using one of the
following two ways:
o ➢bgcolor attribute - You can set background color
for whole table or just for one cell.
o background attribute - You can set background
image for whole table or just for one cell.
o You can also set border color also using bordercolor
attribute
57
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border="1" bordercolor="green" bgcolor="yellow">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td><td>Row 1 Cell 2</td><td>Row
1 Cell 3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
Output
</table> </body>
</html>
58
Table Height and Width
▪ You can set a table width and height using width and height
attributes.
▪ You can specify table width or height in terms of pixels or in
terms of percentage of available screen area.
59
<!DOCTYPE html>
<html>
<head>
<title>HTML Table
</head>
<body>
<table border="1"
<tr>
<td>Row 1, Column
<td>Row 1, Column
</tr>
<tr>
<td>Row 2, Column
<td>Row 2, Column
</tr>
</table>
</body>
</html>
Width/Height</title>
width="400" height="150">
1</td>
2</td>
Output
1</td>
2</td>
60
Table Caption
▪ The caption tag will serve as a title or explanation for the table and it
shows up at the top of the table.
<!DOCTYPE html>
<html>
<head>
<title>HTML Table
Caption</title>
</head>
<body>
<table border="1" width="100%">
<caption>This is the caption</caption>
<tr> <td>row 1, column
1</td><td>row 1, column 2</td>
</tr> <tr>
<td>row 2, column 1</td><td>row 2,
column 2</td>
</tr>
</table>
</body>
</html>
61
HTML – LISTS
▪ HTML offers web authors three ways for specifying lists of
information. All lists must contain one or more list elements.
▪ Lists may contain:
o <ul> - An unordered list: This will list items using plain
bullets.
o <ol> - An ordered list: This will use different schemes of
numbers to list your items.
o <dl> - A definition list: This arranges your items in the same
way as they are arranged in a dictionary.
62
Unordered HTML List
▪ An unordered list starts with the <ul> tag.
▪ Each list item starts with the <li> tag.
▪ The list items will be marked with bullets (small black circles) by
default:
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
63
Unordered HTML List - Choose List Item Marker
▪ The CSS list-style-type property is used to define the style
of the list item marker:
64
Example - Disc
<ul
style="list-style-type:disc">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example - Circle
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
65
Example - Square
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example - None
<ul style="list-style-type:none">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
66
Ordered HTML List
▪ An ordered list starts with the <ol> tag. Each list
item starts with the <li> tag.
▪ The list items will be marked with numbers by
default:
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Ordered HTML List - The Type Attribute
▪ The type attribute of the <ol> tag, defines the type of the
list item marker:
67
Numbers:
<ol type="1">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
68
Uppercase Letters:
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Lowercase Letters:
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Uppercase Roman Numbers:
<ol type="I">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
69
Lowercase Roman Numbers
:
<ol type="i">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
HTML Description Lists
▪ HTML also supports description lists.
▪ A description list is a list of terms, with a description of each
term.
▪ The <dl> tag defines the description list, the <dt> tag defines the
term (name), and the <dd> tag describes each term:
70
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Nested HTML Lists
▪ List can be nested (lists inside lists):
Example
<ul> <li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul> </li> <li>Milk
</li>
</ul>
71
Horizontal Lists
▪ HTML lists can be styled in many different ways with CSS.
▪ One popular way is to style a list horizontally, to create a menu:
72
HTML – TEXT LINKS
▪ A webpage can contain various links that take you directly to other pages and
even specific parts of a given page.
▪ These links are known as hyperlinks.
▪ Hyperlinks allow visitors to navigate between Web sites by clicking on words,
phrases, and images.
Linking Documents
▪ A link is specified using HTML tag <a>.
▪ This tag is called anchor tag and anything between the opening <a> tag and
the closing </a> tag becomes part of the link and a user can click that part to
reach to the linked document.
▪
Following is the simple syntax to use <a> tag.
<a href="Document URL" ... attributes-list>Link Text</a>
73
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href=http://www.tutorialspoint.com target="_self">Tutorials
Point</a>
</body>
</html>
The target Attribute
▪ We have used target attribute in our previous example.
▪ This attribute is used to specify the location where linked document is
opened.
▪ Following are the possible options:
74
75
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click any of the following links</p>
<a href="/html/index.htm" target="_blank">Opens in New</a> |
<a href="/html/index.htm" target="_self">Opens in Self</a> |
<a href="/html/index.htm" target="_parent">Opens in Parent</a> |
<a href="/html/index.htm" target="_top">Opens in Body</a>
</body>
</html>
HTML – BACKGROUNDS
▪ Html Background with Colors
▪ Html Background with Images
• By default, your webpage background is white in color.
• You may not like it, but no worries. HTML provides you following
two good ways to decorate your webpage background
76
Html Background with Colors
▪ The bgcolor attribute is used to control the background of an HTML
element, specifically page body and table backgrounds.
▪ Following is the syntax to use bgcolor attribute with any HTML tag.
<tagname bgcolor="color_value"...>
▪ This color_value can be given in any of the following formats:
<!-- Format 1 - Use color name -->
<table bgcolor="lime" >
<!-- Format 2 - Use hex value -->
<table bgcolor="#f1f1f1" >
<!-- Format 3 - Use color value in RGB terms -->
<table bgcolor="rgb(0,0,120)" >
77
Html Background with Images
▪ The background attribute can also be used to control the background
of an HTML element, specifically page body and table backgrounds.
▪ You can specify an image to set background of your HTML page or
table. Following is the syntax to use background attribute with any
HTML tag.
• Note: The background attribute is deprecated and it is recommended
to use Style Sheet for background setting.
<tagname background="Image URL"...>
78
<!DOCTYPE html>
<html>
<head>
<title>HTML Background Images</title>
</head>
<body>
<!-- Set table background -->
<table background="/images/html.gif" width="100%“
height="100">
<tr><td>
This background is filled up with HTML image.
</td></tr>
</table>
</body>
</html>
79
HTML – COLORS
▪ Colors are very important to give a good look and feel to your website.
You can specify colors on page level using <body> tag or you can set
colors for individual tags using bgcolor attribute.
▪ The <body> tag has following attributes which can be used to set
different colors:
o ➢ bgcolor - sets a color for the background of the page.
o ➢ text - sets a color for the body text.
o ➢ alink - sets a color for active links or selected links.
o ➢ link - sets a color for linked text.
o ➢ vlink - sets a color for visited links - that is, for linked text that
you have already clicked on.
80
How to code colors
81
RGB Values
▪ This color value is specified using the rgb( ) property.
▪ This property takes three values, one each for red,
green, and blue.
▪ The value can be an integer between 0 and 255 or a
percentage.
82
83
FORMS
▪ HTML Forms are required, when you want to collect
some data from the site visitor.
▪ For example, during user registration you would like to
collect information such as name, email address,
credit card, etc.
▪ A form will take input from the site visitor and then
will post it to a back-end application such as CGI, ASP
Script or PHP script etc.
84
<form action="Script URL" method="GET|POST">
form elements like input, textarea etc.
</form>
85
HTML Form Controls
▪ There are different types of form controls that you can
use to collect data using HTML form:
o ✓ Text Input Controls
o ✓ Checkboxes Controls
o ✓ Radio Box Controls
o ✓ Select Box Controls
o ✓ File Select boxes
o ✓ Hidden Controls
o ✓ Clickable Buttons
o ✓ Submit and Reset Button
86
The INPUT Tag
▪ The INPUT tag is a multipurpose tag that creates many
different types of controls
▪ The type of input is controlled by the TYPE attribute – Can be
TEXT, PASSWORD, CHECKBOX, RADIO, SUBMIT,
RESET, FILE, or BUTTON
▪ ➢
Almost all of these should have a NAME attribute
▪ ➢
Their initial state can be set with a VALUE attribute
▪ ➢
They can all be disabled with DISABLE
▪ ➢
An INPUT tag is never closed (no )
87
Checkbox
▪ The CHECKED attribute (with no value) is used to indicate a pre-checked
checkbox
▪ The VALUE attribute specifies the value bound to name if this checkbox is
submitted (default = ON)
Check all that apply:<br>
<input type="checkbox" name="dogs">I like dogs<br>
<input type="checkbox" name="cats">I like cats<br>
<input type="checkbox" name="pigs">I like pigs
Note: For Checkbox, names
different but values are
the same
88
Radio Boxes
▪ <input type="radio" ...>
▪ Used when user is to select one of many mutually exclusive options
▪ Radio buttons with same name form a group of mutually exclusive options
<input type="radio" name="agree"
checked value="a">I
agree completely<br>
<input type="radio" name="agree" value="b">I agree a
little<br>
<input type="radio" name="agree" value="c">I disagree
a little<br>
<input type="radio" name="agree" value="d">I disagree
completely<br>
Note: For radio buttons, names are the
same but values are different
89
Text Boxes
▪ <input type="text" ...>
▪ Allows entry of one line of text (Actually, not completely true – try
cut and paste)
▪ Attribute SIZE specifies the width (in characters)
▪ Attribute MAXLENGTH specifies the maximum number of
characters
User's full name:
<input name="fullname" type="text" size="30"
maxlength="50">
90
Passwords
▪ <input type="password" ...>
▪ Identical to a text box, but text typed into the box is not readable
▪ Useful for submitting sensitive information (like passwords)
Buttons
▪ <input type="submit" ...> : Creates a button that submits the form
to the server
▪ <input type="reset" ...> : Creates a button that resets all form
fields to their default state
▪ <input type="button" ...> : Creates a button that does nothing
Example: <input type="submit" value="Submit Form Data">
91
Text Areas
▪ The TEXTAREA tag provides a multiline text entry area
▪ The ROWS and COLS attributes are required and they specify the number
of rows and number of columns
<textarea rows="30" cols="50" name="bigtext">
The preformatted initial text is sandwiched within
the tag.
</textarea>
92
Menus
▪ Drop-down menus are created using the SELECT tag
▪ Attribute SIZE determines how many rows to display at once
▪ Each option is enclosed in an OPTION tag
<select name="country" size="5">
<option value="AB">Abkhazia</option>
...
<option value="ZB">Zimbabwe</option>
</select>
▪
The MULTIPLE attribute of the SELECT tag creates menus that allow
multiple selections
▪
Options can be grouped hierarchically using the OPTGROUP tag
93
Download