Lecture 2ABC
Lecture 2ABC
• HTML5
• P, pre
• Lists, color, style
• Hyperlink
• Absolute vs relative
paths
• Block vs inline
elements
• Tables
• Forms
2
HTML - Fundamentals
<html>
<head>
</head>
<body>
<p align="center">
<font face="Arial" color="red" size="3">
<h1>Mike Tyler</h1>
PO Box 190387<br>
Hungry Horse, Mt 59919<br></font>
<img src="file:///c:/mike.jpg"/>
</p>
</body>
<html>
Output
3
HTML - Fundamentals
<html>
<head>
</head>
<body>
<p align="center">
<font face="Arial" color="red" size="3">
<h1>Mike Tyler</h1>
PO Box 190387<br>
Hungry Horse, Mt 59919<br></font>
<img src="file:///c:/mike.jpg"/><br>
<a href=“biopage.html”>Read my Bio</a>
</p>
</body>
<html>
4
HTML -
Fundamentals
Output
5
HTML – Paragraph vs Preformatted Text
<html> <html>
<head> </head> <head> </head>
<body> <body>
<p> <pre>
My Bonnie lies over the ocean. My Bonnie lies over the ocean.
My Bonnie lies over the sea. My Bonnie lies over the sea.
My Bonnie lies over the ocean. My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me. Oh, bring back my Bonnie to me.
</p> </pre>
</body> </body>
<html> <html>
6
HTML – Paragraph vs Preformatted Text
<html> <html>
<pre>: fixed-width font (usually
<head> </head> <head> </head>
Courier), and it preserves both spaces
<body> and line breaks
<body>
<p> <pre>
My Bonnie lies over the ocean. My Bonnie lies over the ocean.
My Bonnie lies over the sea. My Bonnie lies over the sea.
My Bonnie lies over the ocean. My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me. Oh, bring back my Bonnie to me.
</p> </pre>
</body> </body>
<html> <html>
7
HTML – Fundamentals: Lists
8
HTML – Fundamentals
Lists
Unordered list Ordered list
9
HTML – Fundamentals: Heading
10
HTML – Fundamentals: Horizontal
Lines and Comments
• Horizontal Line
• The <hr /> tag is used to create an horizontal rule (line).
<p>This is a paragraph</p>
<hr/>
• Comments
• Comments are ignored by the browser and are not displayed.
• Make the code readable and understandable
<!-- This is a comment -->
11
Entity
Character Description
Name
space
< less than < Handling
Special
> greater than > Characters
& ampersand &
quotation
" "
mark
12
HTML – Fundamentals: Colors
color = “red” Color HEX RGB
#000000 rgb(0,0,0)
color = “#FF0000”
#FF0000 rgb(255,0,0)
Hexadecimal values: 00 to FF #00FF00 rgb(0,255,0)
0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f #0000FF rgb(0,0,255)
#FFFF00 rgb(255,255,0)
#00FFFF rgb(0,255,255)
#FF00FF rgb(255,0,255)
#FF FF FF #C0C0C0 rgb(192,192,192)
#FFFFFF rgb(255,255,255)
Red Blue
Green
13
HTML – Fundamentals: Style
Attribute
14
HTML – Fundamentals: Style
<html>
<body style="background-color : PowderBlue;">
<h1>Look! Styles and colors</h1>
<p style="font-family:verdana; color:red">
This text is in Verdana and red
</p>
<p style="font-family:times; color:green">
This text is in Times and green
</p>
<p style="font-size:30px">This text is 30 pixels high</p>
</body>
</html>
15
HTML –
Fundamentals: Style
<html>
<body style="background-color : PowderBlue;">
<h1>Look! Styles and colors</h1>
<p style="font-family:verdana; color:red">
This text is in Verdana and red
</p>
<p style="font-family:times; color:green">
This text is in Times and green
</p>
<p style="font-size:30px">This text is 30 pixels
high</p>
</body>
</html>
16
Hyperlinks: Essence of Hypertext
• Anchor Tag
<a href="url">link text</a>
17
More about Hyperlinks
<a href="https://www.w3schools.com/">Visit
<a>
18
Hyperlinks - The
Target Attribute
• The target attribute specifies where
to open the linked document.
19
More about
Hyperlinks
• Target Attribute
• <a href=“url” target=“_blank”>…</a>
20
More about Hyperlinks
21
Block vs Inline Elements
• A block-level element • An inline element does
always starts on a new line,
and the browsers not start on a new line.
automatically add some
space (a margin) before and
after the element. • An inline element only
takes up as much width as
• A block-level element always necessary.
takes up the full width
available (stretches out to
the left and right as far as it
can). • This is a <span> element
inside a paragraph.
• Two commonly used block
elements are: <p> and <div>.
22
Block vs Inline Elements – Examples
• Block-level elements
• Inline elements
23
HTML Tables
Tables
25
Table Attributes
• BORDER=value
• CELLSPACING=value
• CELLPADDING=value
• WIDTH=value|percent
26
Table Attributes
<TABLE BORDER=1 WIDTH=“50%" CELLPADDING=“6” CELLSPACING=“2”
ALIGN="RIGHT">
<CAPTION ALIGN="bottom">Class Grades</CAPTION>
<TR>
<TH>Student</TH>
<TH>Grade</TH>
</TR>
<TR>
<TD>Tom</TD>
<TD>B+</TD>
</TR>
<TR>
<TD>Sue</TD>
<TD>A-</TD>
</TR>
</TABLE>
27
Tables: Rowspan vs Colspan
28
Table:
Rowspan vs
Colspan
29
Hands-on
30
HTML Forms
What are Forms?
• An HTML form is used to collect user input
and send it to the server for processing
1. action=“url” (required)
• Specifies where to send the data
when the Submit button is clicked
2. method=“GET" (default)
• Specifies how to submit the data
e.g. through GET or POST
The Action Attribute
• The action attribute defines the action to be performed when the form is
submitted.
• Usually, the form data is sent to a file on the server when the user clicks on the
submit button.
34
<html>
<body>
<form name="form1" action="next.html"
method="get">
The Method name:<input type ="text" id="name" name="name">
<input type="submit" value="next" >
Attribute </form>
</body>
</html>
35
Method = GET or POST
36
Method = GET vs POST
• The HTML <input> element is the most
used form element.
The <input> • An <input> element can be displayed in
Element many ways, depending on
the type attribute
38
Text Fields
39
Radio Buttons
40
Checkboxes
41
The <select> Element
• The <select> element defines a drop-down list:
• The <option> elements defines an option that can be
selected.
• By default, the first item in the drop-down list is selected.
42
The <textarea> Element
• The <textarea> element defines a multi-line input field (a text area):
• The rows attribute specifies the visible number of lines in a text area.
• The cols attribute specifies the visible width of a text area.
43
Further Reading
• https://www.w3schools.com/html/html_tables.asp
• https://www.w3schools.com/html/html_styles.asp
• https://www.w3schools.com/html/html_lists.asp
• https://www.w3schools.com/html/html_forms.asp