HTML and CSS For Beginners
HTML and CSS For Beginners
HTML and CSS For Beginners
with HTML5
ii
iii
Mark Lassoff
LearnToProgram, Inc.
Vernon, Connecticut
iv
LearnToProgram.tv, Incorporated
27 Hartford Turnpike Suite 206
Vernon, CT 06066
[email protected]
(860) 840-7090
2013 by LearnToProgram.tv, Incorporated
ISBN-13: 978-0-9888429-1-5
ISBN-10: 0988842912
All rights reserved. No part of this document may be reproduced or
transmitted in any form or by any means, electronic, mechanical,
photocopying, recording, or otherwise, without prior written permission of
LearnToProgram.tv, Incorporat ed.
Limit of Liability/Disclaimer of Warranty: While the publisher and
author have used their best efforts in preparing this book, they make
no representations or warranties with respect to the accuracy or
completeness of the contents of this book and specifically disclaim any
implied warranties of merchantability or fitness for a particular purpose.
No warranty may be created or extended by sales representatives or
written sales materials. The advice and strategies contained herein may
not be suitable for your situation. You should consult with a professional
where appropriate. By following the instructions contained herein, the
reader willingly assumes all risks in connection with such instructions.
Neither the publisher nor author shall be liable for any loss of profit
or any other commercial damages, including but not limited to special,
incidental, consequential, exemplary, or other damages resulting in whole
or part, from the readers use of, or reliance upon, this material.
Mark Lassoff, Publisher
Kevin Hernandez, VP Production
Alison Downs, Copy Editor
Alexandria OBrien, Book Layout
Jimda Mariano, Technical Writer
Karen Doyle, Intern
vi
vii
Dedication
Thank you Kevin, who worked tirelessly to take the original video course
and edit it into something that made sense. Thank you to Jimda, Alison,
and Alex who made this book possible.
viii
ix
Table of Contents
About the Author................................................................................xv
About the Course Producer................................................................. xv
Chapter 1: Welcome to HTML.........................................................19
1.1 Web Development Technologies...............................................19
Question for Review............................................................................ 21
1.2 Hello World with HTML..............................................................22
Code Listing: Basic Document Structure........................................... 22
Questions for Review........................................................................... 25
Lab Activity......................................................................................... 26
1.3 Basic Document Structure HTML 4.01/XHTML....................27
Code Listing: Basic Document Structure HTML 4.01....................... 28
The Default Stylesheet........................................................................ 29
Code Listing: DOCTYPE Declaration................................................ 29
Code Listing: XHTML Basic Document Structure........................... 30
Questions for Review........................................................................... 31
Lab Activity......................................................................................... 32
1.4 Basic Document Structure HTML5..........................................33
Code Listing: HTML5 Basic Document Structure............................. 33
Questions for Review........................................................................... 34
1.5 Using Comments in HTML.........................................................37
Code Listing: Using Comments in HTML......................................... 37
Questions for Review........................................................................... 38
Lab Activity......................................................................................... 39
1.6 HTML Head Elements.................................................................40
Code Listing: HTML Head Elements................................................. 40
Questions for Review........................................................................... 42
Chapter 1 Lab Exercises...................................................................42
Chapter 1 Summary...........................................................................43
Chapter 2: Text Markup....................................................................44
2.1 Text Markup..................................................................................44
Code Listing: HTML Text Markup..................................................... 45
Questions for Review........................................................................... 46
Lab Activity......................................................................................... 47
2.2 Div and Span Tags.......................................................................48
Code Listing: Div and Span Tags...................................................... 49
Questions for Review........................................................................... 50
x
Lab Activity......................................................................................... 50
2.3 HTML5 Text Markup Tags.........................................................52
Code Listing: HTML5 Tags................................................................ 52
Questions for Review........................................................................... 55
Lab Activity......................................................................................... 56
2.4 Selecting Text Color, Font, and Font Size..............................58
Colors on the Web................................................................................ 58
Code Listing: Inline CSS.................................................................... 59
Code Listing: CSS Style Sheet............................................................ 61
Code Listing: Styling Divs.................................................................. 63
Questions for Review........................................................................... 65
Lab Activity......................................................................................... 66
2.5 Text Alignment, Decoration, Indentation and Text
Transformation...................................................................................70
Code Listing: CSS Example............................................................... 70
Code Listing: Style Example.............................................................. 73
Questions for Review........................................................................... 75
Chapter 2 Lab Exercises................................................................... 77
Chapter 2 Summary...........................................................................78
List of Tags, Styles and Terminologies Introduced...................78
Chapter 3: Working with Lists........................................................80
3.1 Ordered Lists.................................................................................80
Code Listing: Ordered Lists - default................................................. 81
Code Listing: Ordered Lists type=I................................................ 82
Code Listing: Ordered Lists typei.................................................. 83
Code Listing: Ordered Lists: type=A................................................. 85
Code Listing: Ordered Lists type=a............................................... 86
Questions for Review........................................................................... 88
Lab Activity......................................................................................... 89
Lab Solution........................................................................................ 90
3.2 Unordered Lists............................................................................92
Code Listing: Unordered List - default.............................................. 92
Code Listing: Unordered List - <ul type=square>............................ 94
Code Listing: Unordered List - <ul type=circle>.............................. 95
Code Listing: Unordered List - <ul type=disc>................................ 97
Questions for Review........................................................................... 98
Lab Activity......................................................................................... 99
Lab Solution...................................................................................... 100
3.3 CSS for Lists................................................................................102
Code Listing: Unordered Lists......................................................... 104
xi
Page2Excss.HTML............................................................................ 177
Lab Solution Image Embedding, External CSS
Page3Excss.HTML............................................................................ 178
Lab Solution Image Embedding, External CSS
Page2Excss.HTML............................................................................ 180
Lab Solution External CSS Filename: ch5LabSol.CSS............... 181
Chapter 5 Summary.........................................................................182
List of Tags, Styles and Terminologies Introduced.................183
Chapter 6: Tables..............................................................................184
6.1 Creating Tables with HTML....................................................184
Code Listing: HTML Tables............................................................. 185
Questions for Review......................................................................... 187
Lab Activity....................................................................................... 188
Lab Solution:..................................................................................... 189
6.2 Styling Tables with CSS...........................................................191
Code Listing: Styling Tables............................................................ 196
Questions for Review......................................................................... 199
Chapter 6 Lab Exercises.................................................................200
Lab Solution...................................................................................... 202
Chapter 6 Summary.........................................................................207
List of Tags, Styles and Terminologies Introduced.................207
Chapter 7: HTML Forms.................................................................204
7.1 Creating Text Form Elements.................................................208
Code Listing: Creating a form.......................................................... 210
Questions for Review......................................................................... 211
Lab Activity....................................................................................... 212
7.2 Creating Radio Button and Checkbox Elements................214
Code Listing: Radio Button and Checkbox Elements...................... 215
Questions for Review......................................................................... 218
Lab Activity....................................................................................... 218
7.3 New HTML5 Form Elements....................................................221
Code Listing: HTML5 Form Elements............................................. 223
Questions for Review......................................................................... 225
7.4 Creating Multi-Select Elements..............................................226
Code Listing: Multi-Select Elements................................................ 227
Questions for Review......................................................................... 228
Lab Activity....................................................................................... 229
Chapter 7 Lab Exercises.................................................................230
xiii
xiv
xv
xvi
xvii
xviii
19
Chapter 1
Welcome to HTML
Chapter Objectives:
You will be able to identify various web development technologies.
You will be able to create basic HTML 4.01 and XHTML document
structures.
You will be able to construct a basic HTML5 document structure.
You will be able to understand and implement basic HTML tags.
You will be able to use HTML head elements.
You will be able to understand the purpose of and create comments in
HTML.
20
Technology/
Language
Role
HTML
CSS
Javascript
PHP
MySQL
21
Perl
.net Languages
AJAX
22
Title
Body
FIGURE 1 - 1
In the HTML code, several tags and elements were used to create the
document. First we will list the generic HTML terms and then discuss
the intended function of each tag.
Opening Tag: The opening tag opens each element. It is
comprised of the tag name surrounded by brackets. Examples:
<p>, <title>, <body>.
Closing Tag: The closing tag closes each element. It is
comprised of the same tag name as the opening tag but is
preceded by a slash. Examples: </p>, </title>, </body>.
Content: Exists between the opening and closing tag. Content
may be text contentwhich is output to the browser window,
or other tags that are interpreted by the browser.
24
Tag
Purpose
<html>
<head>
25
<body>
<p>
26
Lab Activity
Create an HTML page that outputs in the browser exactly like the
following screenshot. Notice that there are messages both in the
browser window and on the tab at the top of the browser itself.
FIGURE 1 - 2
Type this code into your text editor and then add the necessary missing
code to produce the previous output.
27
28
FIGURE 1 - 3
29
30
The basic document structure for an XHTML document looks like this:
FIGURE 1 - 4
31
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en">
Within the opening tag you will notice several attribute/value pairs.
These pairs indicate that we are using a specific namespace for our XML
document. In this case, its the XML namespace. Its not critical you
understand the idea of namespace in this contextits purpose is basically
vestigial at this point. However, you will see the concept of attribute
value pairs again.
Often within opening tags you will see a set of attribute value pairs.
An equal sign always follows the attribute and the value will always be
surrounded by quotes. The purpose of an attribute value pair is to modify
the tag in some way. For now, just be familiar with the structure within
the opening tag of an element.
32
Lab Activity
This coding activity explores the importance of using comments in your
HTML code. Follow the directions to create an HTML document that has
embedded comments.
Create an HTML document.
Use separate <p> tags to display your name, address and phone number.
Use comment tags to create three separate lines of comments.
In one comment, identify who you are and the (potentially fictional)
company you work for.
Identify the purpose of the page in another comment.
Finally, create a comment that identifies the function of a line of code.
This is what your output should look like:
FIGURE 1 - 5
33
FIGURE 1 - 6
34
Its important to note that the browser does not alter its behavior or the
way it interprets tags based on the basic document structure version that
you use. These structures simply make the document valid and declare
the HTML standard that you are using.
You can validate your code and ensure it complies with a particular
existing standard by pasting your code into the text box located at:
http://validator.w3.org/#validate_by_input
FIGURE 1 - 7
36
8. If you are using the XHTML standard, what element should appear first
in your code?
a. A language declaration
b. A W3 declaration
c. An HTML declaration
d. An XML declaration
9. In HTML5, what element should begin your code?
a. <!DOCTYPE html>
b. <htmltype html>
c. <version HTML5>
d. <content HTML5>
10. Where are comments visible?
a. In the browser bar.
b. On the title.
c. In the body of the page.
d. Only in the code.
11. Which symbol is used to begin HTML comment elements?
a. <?-b. <!-c. <#-d. <+-12. Where do metatags allow you to put information about your webpage?
a. Within the body of a document.
b. Within the title of a document.
c. Within the head of the document.
d. Within the comments of a document.
13. Which metatag often will appear as a description in search engine
results?
a. <meta name= description>
b. <meta name= keywords>
c. <meta name= comments>
d. <meta name= author>
37
Comments in HTML start with the symbol: <!-Comments in HTML terminate with the symbol: -->
In the example below, comments are used in two ways. First, the
comments are used to place some documentation in the document head.
Second, they are used to comment out the h1 tag so that it is ignored
by the browser. This is a common technique used when debugging and
attempting to diagnose problems in your code.
38
-->
</head>
<body>
<!-<h1>Welcome to our page</h1>
-->
<p>You are almost done with the
chapter one lectures!</p>
</body>
</html>
As you can see, the comments cause the h1 tag to be ignored, but
otherwise have no effect on the display of the document:
FIGURE 1 - 8
Lab Activity
In this lab activity, your goal is to create a fully functional HTML 4.01
document, containing many of the elements that were discussed in the
chapter. Then convert that document into an HTML5 document.
Create an HTML 4.01 basic document structure that displays your name,
address and phone number in separate paragraph, <p>, tags. Point your
browser at http://validator.w3.org/#validate_by_input. Copy your code
into the large test area and validate it against the 4.01 HTML standard.
Note any errors. If necessary, correct your code and validate it again until
it is free of errors.
Modify the document created in the first step of the lab so it conforms to
the XHTML standard. Go back to the HTML validator page and again
validate your code. (Dont forget to click the More Options tab and
validate against the XHTML standard.) Again note any errors. Correct
them and validate again ensuring your code is correct.
Convert your document to an HTML5 document type and display it in at
least two different browsers. Note the way these browsers render HTML
content differently.
40
Name
Purpose
Description
Keywords
Author
You will notice that the http-equiv attribute is also used to declare the
character set used for the page. This type of meta tag is not frequently
used in contemporary HTML authoring.
FIGURE 1 - 9
42
Chapter 1 Summary
In Chapter 1, we discussed the basics of HTML, including
different web development technologies and how each technology
is used. We also reviewed how to declare different types of HTML
documents, such as HTML 4.01, XHTML and HTML5.
We examined basic tags in HTML and how each tag works. You
discovered how to create your own HTML page containing text.
We detailed various HTML elements including the title and head
elements. We also discussed how to add comments to your HTML
code. After reading this chapter, you should be able to build your
own basic HTML page.
In the next chapter we will discuss text markup and how to use
CSS with HTML to style your webpage.
44
Chapter 2
Text Markup
Chapter Objectives:
You will be able to understand and apply HTML text markup.
You will be able to implement semantic text markup.
You will be able to use HTML5 markup.
You will be able to understand Cascading Style Sheets.
You will be able to style elements of HTML using CSS attributes.
You will be able to create a CSS style sheet and link it to a webpage.
<p>
<br>
<strong>
46
This is how the code will look when viewed in the browser. Notice how
each subsequent header gets smaller and how the <strong> tag makes
the text bold and the <em> tag changes the text to italics.
H1
H2
H3
H6
P
Strong
EM
FIGURE 2 - 1
47
Lab Activity
Create an HTML page that outputs in the browser exactly like the
following screenshot. Notice how each subsequent header gets smaller,
and how the <strong> tag makes the text bold and the <em> tag
changes the text to italics.
FIGURE 2 - 2
48
Type this code into your text editor and then add the necessary missing
code to produce the output above.
</body>
</html>
49
50
FIGURE 2 - 3
Lab Activity
Create an HTML page that outputs in the browser exactly like the
following screenshot:
51
FIGURE 2 - 4
Type this code into your text editor and then add the necessary missing
code to produce the output above.
52
<footer>
<aside>
<nav>
Other new HTML5 tags include <aside> which is designed
to contain secondary content on the main page, <nav> which
is used to store navigational elements and <article> which is meant to
contain articles on the page. Once again, these elements wont alter the
appearance of text, but are used to help style content
<article>
using CSS.
This is an example of text markup with HTML5 tags.
<!DOCTYPE html>
<html>
<head>
<title>HTML5 Markup</title>
53
</head>
<body>
<header>
<h1>Welcome to our HTML 5 Layout Site</
h1>
<h2>From the HTML and CSS (with HTML5)!
Course</h2>
</header>
<aside>
<h3>News from the Homefront</h3>
<p>This news is going in an aside. It
is secondary to the <mark>main content</
mark> on the page.</p>
</aside>
<aside>
<h3>More News from the Homefront</h3>
<p>This is a second aside.</p>
</aside>
<nav>
<p>Company News</p>
<p>About Us</p>
<p>Our Products</p>
<p>Contact Us</p>
</nav>
<article>
<h3>How to Cook for One</h3>
<section>
<p>Cooking for one is a challenge. It
can be both expensive and time consuming if
not done correctly</p>
</section>
<section>
<h3>Recipes for One</h3>
</section>
</article>
<footer>
<p>Copyright 2011 | Mark Lassoff |
2.3 HTML5 Text Markup Tags
54
LearnToProgram.tv</p>
</footer>
</body>
</html>
Footer
Article
Nav
This is how the texts would look when displayed by the browser.
55
FIGURE 2 - 5
<mark>
Another markup tag used in the example is <mark>. It does not alter the
layout of the text, but supports the display of the text as seen below.
56
Lab Activity
Create an HTML page that outputs in the browser exactly like the following
screenshot:
FIGURE 2 - 6
57
<!DOCTYPE html>
<html>
<head>
<title>HTML5 Markup</title>
</head>
<body>
</body>
</html>
58
59
0123456789ABCDEF
A color is least intense at 0 and most intense at F. So if you wanted the
most intense blue, it would be #0000FF. Your tag would be:
60
<style type="text/css">
Once you have written the style tag you can define the element you want
to style. Simply indicate the element. When you write your element using
CSS it is referred to as a selector. You dont need parentheses or brackets
when indicating the selector. Once you have established the selector you
wish to style, you need to place the style attributes within curly brackets.
The following code shows you an example of how to do this:
Times, serif;
h2
Times, serif;
color: rgb(155,70,150);
font-family: Georgia,
font-size: 2em;
}
{
color: rgb(10,50,100);
font-family: Georgia,
font-size: 1.25em;
2.4 Selecting Text Color, Font, and Font Size
62
}
p
{
color: rgb(0,0,185);
font-family: arial,
verdana, sans-serif;
font-size: .75em;
}
#footer {
font-family: arial,
verdana, sans-serif;
font-size: .5em;
}
.smaller{
font-size: .65em;
}
Notice how the curly bracket is on the same line as the tag, while each
style attribute is on a separate line. While this format is not required,
it does make your CSS code easy to read and maintain. Each style and
value must terminate with a semi-colon to function and each set of styles
must end with a curly bracket. You can style elements with multiple
attributes, but be aware that when you style an element you are altering
every implementation of that element in the documents HTML code.
There are many attributes you can use to change the appearance of
elements. In the example above, we changed the font with the fontfamily style and the typeface size with the font-size style. Browsers may
interpret the attributes in various ways, or users may not have a specific
font available, so it is always a good idea to put
multiple fonts in your styles.
Font Sizes:
pt - points
64
FIGURE 2 - 7
The third way to apply CSS is to create the CSS in a separate document.
This method is great for keeping the styles consistent on multiple pages.
To use the external CSS method, you need to create a new document
and add .css as the extension. For example, you could create a document
titled style.css.
For an external style sheet you only need to write the selectors and
associated styles. You do not need to include a style tag in the external
document.
To include external CSS styles in any HTML page you use a simple link
to the CSS file. This is an example of a proper link tag:
65
66
Lab Activity
In this activity, the CSS code has been removed from the HTML
document. Add the necessary CSS code in order to make the document
appear like the screenshot.
FIGURE 2 - 8
67
68
70
72
You can align text with the textalign attribute. If you want to
text-align: justify
center the text, use the textLorem ipsum dolor sit amet, consectetur adipiscing
elit.
Pellentesque
suscipit felis quis dui et dapibus
align: center attribute. You can
orci tincidunt. Nullam viverra nisl condimentum
also align text using the textdui commodo feugiat. Etiam pretium mauris
accumsan arcu consectetur sodales.
align: justify attribute. Using
justify as your text-align value
aligns the text on both the left side and right side of the document.
text-decoration:
underline
strikethrough
Times, serif;
color: rgb(155,70,150);
font-family: Georgia,
font-size: 2em;
text-align: center;
font-variant: small-caps;
}
h2
Times, serif;
uppercase;
{
color: rgb(10,50,100);
font-family: Georgia,
font-size: 1.25em;
text-transform:
}
{
color: rgb(0,0,185);
font-family: arial,
verdana, sans-serif;
font-size: .75em;
text-align: justify;
text-indent: 20px;
}
#footer {
font-family: arial,
verdana, sans-serif;
2.5 Text Alignment, Decoration, Indentation, and Text Transformation
74
font-size: .5em;
text-decoration: overline;
}
.smaller{
font-size: .65em;
}
This is how the above CSS code styling will look in a browser. Notice the
overline on the footer and the centered header.
FIGURE 2 - 9
75
76
77
Georgia
16pt
Red 215 | Green 0 | Blue 0
Style the text in the lists below the heading tags as follows:
Font:
Font Size:
Color:
Arial
80% of the default style sheet (Use ems)
#0000AB
Using the correct CSS rule, center-align your heading tags and make
them all capital letters (Dont change the text content of the elements.)
78
Chapter 2 Summary
In this chapter, we discussed how to use HTML text markup.
You learned various methods for altering text using HTML. We
also reviewed the new tags that will be available in HTML5. You
discovered how to use <div> and <span> tags as well.
This chapter also gave an introduction and overview of using
CSS to style your HTML. We discussed the three methods
for implementing CSS in your HTML and which method was
appropriate depending on the situation. We also reviewed several
attributes for styling text, including attributes for changing the
color and font. In future chapters, we will go into greater detail on
how to use CSS to make your websites look neat and professional.
In the following chapter, we will discuss how to organize your text
using lists. You will learn how to create ordered and unordered
lists and style your lists using CSS
Definition
Text markup
<h1>
<h2>
<h3>
<em>
<strong>
<span>
<div>
79
<header>
<footer>
<aside>
<nav>
<article>
inline styling
RGB
Hex Colors
80
Chapter 3
Working with Lists
Chapter Objectives:
You will be able to create ordered and unordered lists.
You will be able to alter the bullets of the lists.
You will be able to style the lists using CSS.
<ol>
<li>
The browser numbers each item in an ordered list. However,
you can also style the ordered list using HTML style tags. The
attribute type allows you to use different numbering systems or style for
your lists. See table below:
Attribute Type for
<ol> tag
<ol> (default)
Numbers
<ol type=I>
<ol type=i>
<ol type=A>
<ol type=a>
81
The following examples demonstrate how each of the tags and attributes
are used, followed by an image capture of how it will look after using each
attribute.
82
This is how a default ordered list <ol> looks when viewed in the browser:
<ol> (default)
FIGURE 3 - 1
This is how <ol type=I> will look when viewed in the browser:
FIGURE 3 - 2
84
<title>Ordered Lists</title>
</head>
<body>
<h2>My Five Favorite Cities</h2>
<ol type='i'>
<li>New York City</li>
<li>London</li>
<li>San Francisco</li>
<li>Salt Lake City</li>
<li>Honolulu, Hawaii</li>
</ol>
</body>
<html>
This is how <ol type=i> will look when viewed in the browser:
85
FIGURE 3 - 3
86
This is how <ol type=A> will look when viewed in the browser:
Uppercase Letters/Alphabet
FIGURE 3 - 4
<li>San Francisco</li>
<li>Salt Lake City</li>
<li>Honolulu, Hawaii</li>
</ol>
</body>
</html>
This is how <ol type=a> will look when viewed in the browser:
Lowercase Letters/Alphabet
FIGURE 3 - 5
88
89
Lab Activity
Create an HTML page that will display the following output:
FIGURE 3 - 6
90
Lab Solution
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Strict//EN" "http://www.w3.org/TR/
xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en">
<head>
<title>Ordered Lists</title>
</head>
<body>
<h2>Ordered List</h2>
<ol>
<li>The default is numbered list.</
li>
<li>The default is numbered list.</
li>
<li>The default is numbered list.</
li>
</ol>
<ol type='I'>
<li>Second is uppercase Roman
numeral.</li>
<li>Second is uppercase Roman
numeral.</li>
<li>Second is uppercase Roman
numeral.</li>
</ol>
<ol type='i'>
<li>Third is lowercase Roman
numeral.</li>
<li>Third is lowercase Roman
numeral.</li>
<li>Third is lowercase Roman
91
numeral.</li>
</ol>
<ol type='A'>
<li>Fourth is uppercase English
alphabet.</li>
<li>Fourth is uppercase English
alphabet.</li>
<li>Fourth is uppercase English
alphabet.</li>
</ol>
<ol type='a'>
<li>Last is lowercase English
alphabet.</li>
<li>Last is lowercase English
alphabet.</li>
<li>Last is lowercase English
alphabet.</li>
</ol>
</body>
</html>
92
<ul>
Like ordered lists, you can select the style for the list with the type
attribute. The default is a solid circular bullet, but you can also use other
bullet types such as square bullets or the unfilled circle. Refer to the table
below to see the list of tags used to indicate the bullet type used in an
unordered list.
Attribute Type
for <ul> tag
<ul> (default)
<ul type=square>
Square bullet
<ul type=circles>
<li>PHP</li>
<li>Java</li>
<li>Javascript</li>
<li>C++</li>
<li>Objective C</li>
<li>Visual Basic.net</li>
</ul>
</body>
</html>
This is how a default unordered list <ul> looks when viewed in the
browser:
<ul> (default)
FIGURE 3 - 7
94
95
Square Bullets
FIGURE 3 - 8
96
<li>C++</li>
<li>Objective C</li>
<li>Visual Basic.net</li>
</ul>
</body>
</html>
This is how an unordered list <ul type=circle> will look when viewed
in the browser:
97
FIGURE 3 - 9
Circle Bullets
FIGURE 3 - 10
98
99
Lab Activity
Create an HTML page that will display the following output:
FIGURE 3 - 11
100
Lab Solution
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Strict//EN" "http://www.w3.org/TR/
xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en">
<head>
<title>Unordered Lists</title>
</head>
<body>
<h2>Unordered List</h2>
<ul>
<li>Default type precedes list
with a solid circle.</li>
<li>Default type precedes list
with a solid circle.</li>
<li>Default type precedes list
with a solid circle.</li>
</ul>
<ul type="square">
<li> Second type is 'square'.</li>
<li> Second type is 'square'.</li>
<li> Second type is 'square'.</li>
</ul>
<ul type="circle">
<li> Third type is 'circle'.</li>
<li> Third type is 'circle'.</li>
<li> Third type is 'circle'.</li>
</ul>
<ul type="disc">
<li> Last type is 'disc'.</li>
<li> Last type is 'disc'.</li>
101
102
<head>
<style type="text/css">
ul {
list-style-type: circle;
}
</style>
</head>
With CSS you can also change the margin and padding of your list
using the margin and padding styles. Padding allows you to add space
between the content and the edge of the block containing it. Margin adds
space between the content block and the next element of content on the
page. This code is placed along the list style block portion in the heading
as follows:
<head>
<style type="text/css">
ul {
list-style-type: circle;
padding: 0px;
margin: 0px;
}
</style>
</head>
Many developers and designers use CSS to customize bullet graphics to
improve the look of their site. Setting up a custom bullet is easy. We do
this by including the list item selector (li) inside the style code block and
103
<head>
<style type="text/css">
ul {
list-style-type: circle;
padding: 0px;
margin: 0px;
}
li {
background-image: url(star.png);
background-repeat: no-repeat;
}
</style>
</head>
Finally, its important to change the position of the custom bullet so it
doesnt overlap the text. You can do this by using the backgroundposition attribute and padding-left attribute. However, you must
change your pixel values to work with your custom bullet.
<head>
<style type="text/css">
ul {
list-style-type: circle;
padding: 0px;
margin: 0px;
}
li {
background-image: url(star.png);
3.3 CSS for Lists
104
background-repeat: no-repeat;
background-position: 3px 1px;
padding-left: 20px;
}
</style>
</head>
The complete code set is as follows:
url(star.png);
background-repeat: no-
repeat;
background-position:
3px 1px;
</style>
</head>
105
background-image:
padding-left: 20px;
<body>
<h2>Some Programming Languages</h2>
<ul type="disc">
<li>PHP</li>
<li>Java</li>
<li>Javascript</li>
<li>C++</li>
<li>Objective C</li>
<li>Visual Basic.net</li>
</ul>
</body>
</html>
This is how custom button styling will appear in the browser:
FIGURE 3 - 12
106
United
Delta
Frontier
Hawaiian Air
Virgin America
FIGURE 3 - 13
108
Lab Solution
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Strict//EN" "http://www.w3.org/TR/
xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en">
<head>
<title>Lab 3: Lists</title>
</head>
<body>
<h2>Ten Technology Companies</h2>
<ol>
<li>Dell</li>
<li>Facebook</li>
<li>LinkedIn</li>
<li>Adobe</li>
<li>Apple</li>
<li>Google</li>
<li>Amazon</li>
<li>HP</li>
<li>Motorola</li>
<li>StumbleUpon</li>
</ol>
<h2>US-Based Airlines</h2>
<style type="text/css">
ul
{
list-style-type: none;
padding: 0px;
margin: 0px;
}
ul li
109
background-image:
url(star-bullet.png);
background-repeat: norepeat;
background-position:
3px 1px;
padding-left: 20px;
}
</style>
<ul>
<li>American</li>
<li>US Airways</li>
<li>Southwest</li>
<li>JetBlue</li>
<li>Alaska Air</li>
<li>United</li>
<li>Delta</li>
<li>Frontier</li>
<li>Hawaiian Air</li>
<li>Virgin America</li>
</ul>
</body>
</html>
110
Chapter 3 Summary
In this chapter, you learned about HTML and CSS styling for
ordered and unordered lists and how to set up a custommade bullet graphic.
111
112
Chapter 4
<a href="http://www.yahoo.com">Yahoo!</a>
<p>I get my news from <a href="http://www.
cnn.com>CNN</a></p>
<p>Fly <a href=http://www.jetblue.
com>jetBlue</a></p>
Internal links are written in a similar fashion to external
links. Internal links direct the user to another page within the
same website or domain. If the HTML document you want to
link to is located in the same folder as the original document,
you simply indicate the name of the file in the link. For
example, if you have a file named links.html you would link
it as:
114
Notice that the bottom link (internal link) does not function yet,
but the three external links do.
115
FIGURE 4 - 1
Now, for the internal link Places Id like to visit in the above example
work, a separate HTML file named places.html, contained in a folder
named details_pages must exist. Create a folder now named details_
pages. Copy the code below in a file named places.html and save it in the
folder you just created. Creating this file will ensure that the internal
link Places Id like to visit works.
116
<ul>
<li>Aspen, Co</li>
<li>Monaco</li>
<li>Spain</li>
<li>Dubai</li>
</ul>
<a href="../links.html">Go Back</a>
</body>
</html>
Included at the bottom of this code is the instruction to Go back to the
main page. The ../ preceding the file links.html directs the link pointer
to move up a folder level to locate the page.
This is what the page will look like when viewed in the browser:
Internal Link
FIGURE 4 - 2
117
FIGURE 4 - 3
118
<a name="top"/>
<a href="#Believing">Dont Stop Believing
</a>
<a name="Believing"/>Dont Stop Believing
</a>
119
120
}
p
sans-serif;
font-size: .8em;
}
</style>
</head>
<body>
<div>
<a name="top"/>
<p><a href="#Believing">Dont Stop
Believing...</a><br/>
<a href="#killer">A Killer
Smile</a><br/>
<a href="#people">Meeting the
Right People</a><br/>
<a href="#time">Putting in the
Time</a><br/>
<a href="#success">Creating Your
Own Success</a><br/>
</div>
<div>
<h2><a name="Believing" />Dont Stop
Believing...</h2>
<p>Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Phasellus
sagittis justo ac neque scelerisque
venenatis. Vestibulum sit amet enim leo, sed
suscipit velit. Maecenas vel ipsum arcu,
sit amet lobortis nisi. Vivamus luctus ipsum
aliquam mi aliquet tincidunt. Nam eleifend
hendrerit consectetur. Praesent sed massa
quis arcu malesuada ornare. Quisque non odio
quis ante porttitor vestibulum.</p>
121
122
<div>
<h2><a name="killer"/>A Killer
Smile...</h2>
<p>Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Phasellus
sagittis justo ac neque scelerisque
venenatis. Vestibulum sit amet enim leo, sed
suscipit velit. Maecenas vel ipsum arcu,
sit amet lobortis nisi. Vivamus luctus ipsum
aliquam mi aliquet tincidunt. Nam eleifend
hendrerit consectetur. Praesent sed massa
quis arcu malesuada ornare. Quisque non odio
quis ante porttitor vestibulum.</p>
<p>In hac habitasse platea dictumst.
Suspendisse posuere vehicula libero in
varius. Suspendisse potenti. Mauris sit amet
odio in felis varius accumsan. In vitae
sem ipsum. Fusce faucibus sem id ligula
ornare posuere vehicula elit porta. Ut ac
est felis. Sed et imperdiet nisl. Donec
nec imperdiet enim. Sed metus nisl, rutrum
in interdum at, elementum eu elit. Vivamus
non sapien nec dui vestibulum suscipit
nec vel metus. Suspendisse potenti. Proin
pellentesque, dui eget congue elementum,
ante purus pharetra metus, eget bibendum
lacus neque lacinia est. Morbi rutrum diam
sit amet tellus faucibus egestas. Sed quam
lectus, adipiscing eget placerat in, laoreet
eget ipsum.</p>
<p>Vestibulum viverra, velit non molestie
ultrices, dolor nibh vulputate erat,
quis luctus ligula sem eu lacus. Nunc
ullamcorper, nibh in iaculis gravida, arcu
justo luctus neque, ut laoreet erat lorem
vitae erat. Sed dapibus ligula tempus augue
123
124
126
<a name="Top"/>
and
<a href="#top">Top<a/>
These allowed the user to immediately navigate to the pages top
location.
128
This is what the page will look like when viewed in the browser:
FIGURE 4 - 4
129
130
State
Pseudo-class Selector
plain link
a:link
a:visited
a:hover
TABLE 4 - 1
In this example shown, the link is made red, the font bold, and not
underlined. The CSS code is as follows:
<style type="text/css">
h2
{
font-family: Georgia, serif;
font-size: 1.75em;
}
p
{
font-family: Helvetica, Arial, sans-serif;
font-size: .8em;
}
a:link, a:visited{
color: red;
font-weight: bold;
text-decoration: none;
}
a: hover{
color: red;
font-weight:
bold;
text-decoration: underline;
}
</style>
131
{
font-family: Helvetica, Arial,
font-size: .8em;
}
a:link, a:visited{
color: red;
font-weight: bold;
text-decoration: none;
}
a:hover{
color: red;
font-weight: bold;
text-decoration: underline;
}
</style>
</head>
<body>
132
<div>
<a name="top"/>
<p><a href="#Believing">Dont Stop
Believing...</a><br/>
<a href="#killer">A Killer
Smile</a><br/>
<a href="#people">Meeting The
Right People</a><br/>
<a href="#time">Putting In the
Time</a><br/>
<a href="#success">Creating Your
Own Success</a><br/>
</div>
<div>
<h2><a name="Believing" />Dont Stop
Believing...</h2>
<p>Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Phasellus
sagittis justo ac neque scelerisque
venenatis. Vestibulum sit amet enim leo, sed
suscipit velit. Maecenas vel ipsum arcu,
sit amet lobortis nisi. Vivamus luctus ipsum
aliquam mi aliquet tincidunt. Nam eleifend
hendrerit consectetur. Praesent sed massa
quis arcu malesuada ornare. Quisque non odio
quis ante porttitor vestibulum.</p>
<p>In hac habitasse platea dictumst.
Suspendisse posuere vehicula libero in
varius. Suspendisse potenti. Mauris sit amet
odio in felis varius accumsan. In vitae
sem ipsum. Fusce faucibus sem id ligula
ornare posuere vehicula elit porta. Ut ac
est felis. Sed et imperdiet nisl. Donec
nec imperdiet enim. Sed metus nisl, rutrum
in interdum at, elementum eu elit. Vivamus
non sapien nec dui vestibulum suscipit
nec vel metus. Suspendisse potenti. Proin
pellentesque, dui eget congue elementum,
133
134
136
138
This is how the styling will look when viewed in the browser. Both
visited and unvisited links appear the same.
FIGURE 4 - 5
140
This is how hover style appears when the user is hovering over the link.
Notice that the Putting in the Time link is now underlined.
FIGURE 4 - 6
Link
http://www.cnn.com
http://www.twit.tv
http://www.learntoprogram.tv
http://www.amazon.com
http://www.cancer.org
142
6) Using the CSS styling, adjust the appearance of the links so that they
always appear dark gray. They become underlined only when the user
hovers their mouse over the link text.
7) Below the link American Cancer Society, add text that says See my
other page Place this text as a <p> element.
8) Create a new HTML page using the correct document structure for
HTML 4.01. In the page, place the text This is my other page. Go back to
my first page in the document <body> using <p> tags.
9) Use Go back to my first page as link text to create a link back to the
first page you created.
10) On the original page you created, create a link to the new page you
created using See my other page as link text.
11) Load the file lab_starter.html, which is provided with the course in
your text editor. The link texts found at the top of the page correspond to
the <h3> headings throughout the document.
12) Create named anchors on all of the <h3> tags. Link those named
anchors in the document page. Your links should appear in the section of
the code that looks like this:
<h2>Featuring Anchors</h2>
<p>In the Beginning</br>
This is my Story<br/>
Two Cats and a Cheap Couch<br/>
Finding Myself<br/>
How it Ended</p>
13) Create an anchor and link pair that allows the user to move from the
Back to Top text at the bottom of the page to the very top of the page.
14) Apply the CSS you created in step 6 to this document so that links
appear dark gray and are only underlined when the user is hovering
above them.
143
144
href="http://www.twit.com">TWiT.</a></p>
<p>I am learning HTML with <a
href="http://www.learntoprogram.
tv">LearnToProgram.tv.</a></p>
<p>I purchase a lot of gear from <a
href="http://www.amazon.com">Amazon.</a></
p>
<p>Everyone should donate money to the
<a href="http://www.cancer.org">American
Cancer Society.</a></p>
<p>See my <a href="otherpage.
html">other page</a></p>
</body>
</html>
FIGURE 4 - 7
145
146
to my main page</p>
</body>
</html>
FIGURE 4 - 8
}
a:link, a:visited{
color: gray;
font-weight: bold;
text-decoration: none;
}
a:hover{
color: gray;
font-weight: bold;
text-decoration: underline;
}
</style>
</head>
<body>
<h1>A Page Full of Gibberish</h1>
<h2>Featuring Anchors</h2>
<a name="top"/>
<a href="#beginning">In the Beginning</
a></br>
<a href="#story">This is my Story</
a><br/>
<a href="#cats">Two Cats and a Cheap
Couch</a><br/>
<a href="#finding">Finding Myself</
a><br/>
<a href="#ended">How it Ended</a></p>
<h3><a name="beginning"/>In the
Beginning</h3>
<p>Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Aliquam
sollicitudin ligula a nisl tempus laoreet.
Donec et leo in felis sagittis placerat
et at massa. Cras suscipit iaculis dolor,
a ultrices arcu facilisis vitae. Aliquam
ac felis vel est rhoncus congue aliquam
Final Lab Solutions
148
150
152
sapien.</p>
<p>Nunc ac ipsum quis nisi ullamcorper
aliquet. Fusce nisi dolor, sollicitudin ac
sollicitudin sed, gravida sed turpis. Ut
id velit vitae urna ornare pharetra. Morbi
nunc velit, consectetur vel pulvinar et,
tempor sit amet magna. Class aptent taciti
sociosqu ad litora torquent per conubia
nostra, per inceptos himenaeos. Sed id
leo velit. Nam vel nibh ut est iaculis
elementum. Fusce malesuada velit sit amet
nulla faucibus in blandit arcu ultricies.
In auctor, metus id vehicula tincidunt,
magna lectus sollicitudin ipsum, quis
porttitor felis elit vehicula sem. Donec
ultricies neque sit amet elit pellentesque
laoreet. Mauris id augue faucibus urna
porta porta ut ac enim. Quisque ultrices
bibendum metus ornare ullamcorper. Nulla
sapien nibh, scelerisque ac convallis ac,
consectetur id lacus. Etiam vitae augue
vitae tortor tincidunt porta et quis
tellus. Cras nunc lorem, aliquam non tempor
vel, pharetra vel purus.</p>
<p>Duis sed tempor arcu. Ut tortor
urna, ultrices nec auctor non, interdum
suscipit dolor. Phasellus condimentum leo
a metus adipiscing euismod. Sed adipiscing
neque elementum quam ultricies aliquam.
Integer sodales, dolor nec sagittis
placerat, risus lectus pretium enim, et
consectetur sem odio sit amet massa. Mauris
velit felis, congue ut varius ut, commodo
vel nulla. Nulla nec suscipit leo.</p>
<h3><a name="ended"/>How it Ended</h3>
<p>Nunc ac ipsum quis nisi ullamcorper
aliquet. Fusce nisi dolor, sollicitudin ac
Final Lab Solutions
154
155
Chapter 4 Summary
In this chapter, we discussed how to create internal and external
links on a webpage and how to use anchor links to easily navigate
within a page.
You also learned how to use CSS pseudo-class stylingchanging
the link color before and after it is visited and when the user
hovers over it with a mouse.
The next chapter discusses displaying pictures in your website, and
audio and video embedding using HTML5.
156
Chapter 5
<img>
<img src="javascript.png"/>
When inserting your image, it is recommended that you include the
attribute for alternative textalt. It provides a text representation for
the image when the user is browsing without the image turned on or
when your mobile device has a slow connection. To use the alt attribute,
write it after the file name. If we add the alternative text for the above
example, the code will be as follows:
<a href="http://www.learntoprogram.tv"><img
src="logo_200.png" alt="LearnToProgram.tv
logo"/></a>
Some browsers by default put a border around images. When borders are
not preferred, CSS styling can be used to prevent it from being displayed.
This is done by setting the border attribute of the image selector to
0px, thus removing the unwanted border. The CSS code should now be:
<style type="text/css">
img {
border: 0px;
}
</style>
One of the important things to consider in HTML is how the images
interact with the text on the website. In this example, we have pasted
some text into our document to see how it interacts with the image.
By default and without any style change, the image simply sits on the
same line and texts do not flow around the image. However, in some
instances, you would want the text to flow around the image. To do this,
include in the image tag align= attribute whose value can be set to
right or left. This will allow the text to flow around the image. Using the
previous image tag and after including the align attribute, the code will
now be as follows:
<a href=http://www.learntoprogram.tv><img
src="logo_200.png" alt="LearnToProgram.tv
logo" align=right/></a>
A more convenient way to design the look of your web page is by using
CSS, which will be introduced later in the course. Below is the complete
5.1 Displaying Images, Image Links and Image Styling with CSS
158
FIGURE 5 - 1
160
turned off.
d. To redirect a user to a different website.
3. What CSS attribute should you add to your webpage to make sure you
dont have any borders around a picture with a link?
a. img { border=none;}
b. img { border=0px; }
c. img { border=0;}
d. img { border=null;}
4. What attribute tag should you use to get the text to flow around your
image?
a. flow=
b. Layout=
c. Place=
d. align=
161
<audio>
<audio controls="controls">
In order to link to the actual music file, the source tag file must be given
the audio file name and the audio file type. The source tag for an mp3 file
is:
162
164
<video controls="controls">
Let us use the video file QualitySample.mp4 in our example. To
cue insertion of the video file, the video tag <video> will be used in
conjunction with controls so the user can start or stop the audio. The tag
is as follows:
<source src="QualitySample.mp4"
type="video/mp4" />
However, you may sometimes need to change the size of the video to
accommodate the browser. Its important to note that when the size of the
video is changed, you need to make sure the aspect ratio of the video is
maintained so it does not get distorted. In order to change the size in the
video tag, add the width and height attributes.
FIGURE 5 - 2
166
2. What attribute do you use to set the size and width of a video file?
a. <video controls=controls width= height= >
b. <source src=video file name.type type=video/type />
c. Video=<width= height=
d. <audio controls=controlswidth= height=>
3. How do you specify the video file source and its type when embedding
video in HTML5?
a. <video src=video file name.type type=video/type />
b. Browsers will change the size of video formats.
c. <source src=video file name.type type=video/type />
d. <source=video, type>
167
Page
Image
Caption
Page 2
River.png
Page 3
Tavern.png
Page 4
townHall.
png
9) Add the next and previous text to each of the pages you just created.
10) Go through all four pages and add code so that the next and previous
text become links to the previous and next pages. If the user clicks next
on page 1 they should move to page 2. If the user clicks next on page 4
they should return to page 1, and so on.
11) Make your CSS external and use the <link> tag with correct
attributes on all pages to link to the CSS. This will give all of your pages
a consistent look.
12) Test to ensure that there are no broken links and that all pages
appear consistently styled.
168
The following Lab Solutions are associated with steps 1-9 of the
Chapter 5 Lab Exercises.
169
FIGURE 5 - 3
170
171
Replace bold text with your files pathname. page2.html will contain
details for The Saugatuck River with the image river.png.
FIGURE 5 - 4
172
173
Replace bold text with your files pathname. page3.html will contain
details for The Tavern with the image tavern.png.
FIGURE 5 - 5
174
175
Replace bold text with your files pathname. page4.html will contain
details for The Tavern with the image tavern.png.
FIGURE 5 - 6
176
The following Lab Solutions are associated with steps 10-12 of the
Chapter 5 Lab Exercises.
177
178
FIGURE 5 - 7
html">Previous</a>
<a href="page4excss.html">Next</
a></p>
</body>
</html>
FIGURE 5 - 8
180
181
FIGURE 5 - 9
}
{
sans-serif;
a:link
}
{
}
border: 0px;
color: #000080;
font-family: arial, verdana,
font-size:.75em;
color:green;
text-decoration: none;
182
Chapter 5 Summary
In this chapter we discussed how to place images onto a website
and how to format the text around the image in order to create a
more pleasing look to the webpage.
You also learned how to embed audio and video using HTML5. We
reviewed the importance of using multiple audio and video files to
accommodate different browsers and how to properly resize videos.
In the next chapter, we will be examining how to create HTML
tables. We will also style those tables using CSS for a better
looking website.
183
Definition
Links
<a>
CSS Pseudo-class
font-weight
184
Chapter 6
Tables
Chapter Objectives:
You will be able to create tables using HTML.
You will be able to style tables in HTML.
You will be able to style tables using CSS.
<tr>
<th>
<td>
<tr><th>Player Name</th><th>Player
Position</th><th>Batting Average</th></tr>
This will display the heading all in one row. To add a little enhancement,
let us surround the headings with borders. We do that by including
borders= attribute after the opening table tag as follows:
<table border="value">
Let us now add the rest of the data in the table. To add more rows, we use
the <tr> tag to surround the row, then each cell is introduced using the
185
Chapter 6: Tables
<td>. Therefore, the code for our next row is:
<tr><td>Todd Smith</td><td>Pitcher</
td><td>.125</td></tr>
If you need a cell to span two rows, add the rowspan= attribute within
the <td> tag of the cell that the attribute will span to. For example:
tr
tr
tr
th
caption
th
th
Header
td
td
td
td
Body
td
td
186
</head>
<body>
<table>
<tr>
<th>Player Name</th><th>Player
Position</th>
<th>Batting Average</th>
</tr>
<tr>
<td>Todd Smith</td><td
colspan="2">Pitcher</td>
</tr>
<tr>
<td>Fred Thomas</
td><td>Catcher</td><td>.300</td>
</tr>
<tr>
<td>Jamal Williams</td><td>Left
Field</td><td>.312</td>
</tr>
<tr>
<td>Tommy Thomas</td><td>Center
Field</td><td>.256</td>
</tr>
<caption>Westport Little League
All-Stars</caption>
</table>
</body>
</html>
187
Chapter 6: Tables
This is a complete table code sample and the next image shows how it will
look in the browser. The table is still very plain and in the next section,
CSS will be added to improve the look of our table.
FIGURE 6 - 1
188
4. Which is the correct attribute syntax if you want to create a border for
your table?
a. <border=1>
b. <border>
c. <table =1>
d. <table Border=1>
5. What tag creates cells within a table?
a. <tr>
b. <th>
c. <td>
d. <t>
Lab Activity
Using an HTML5 document, create a table that will produce an output
exactly like the image shown below using table properties introduced in
this subchapter:
FIGURE 6 - 2
189
Chapter 6: Tables
Extra task: Fill in missing information in the blank cells and
update the following codes.
Lab Solution
<!DOCTYPE html>
<html>
<head>
<title>Tables</title>
</head>
<body>
<table border="5">
<tr>
<th>Sport Name</th><th>Number of Players
per Team</th><th>Points to Win</th>
</tr>
<tr class="odd">
<td>Hockey</td><td></td><td></
td>
</tr>
<tr class="even">
<td>Football</td><td></
td><td></td>
</tr>
<tr class="odd">
<td>Baseball</td><td>9</
td><td></td>
</tr>
<tr class="even">
<td>Basketball</td><td>10-20, 5 on court</
td><td>maximum points earned against
opponent</td>
</tr>
<tr class="odd">
<td>Volleyball</td><td>6</
td><td></td>
6.1 Creating Tables with HTML
190
</tr>
<tr class="even">
<td>Water Polo</td><td>7-6 field
players and 1 goal player</td><td></td>
</tr>
<tr class="odd">
<td>Rowing</td><td>varies on
type of boat</td><td>first to reach goal</
td>
</tr>
<tr class="even">
<td>Rugby League</td><td>13</
td><td></td>
</tr>
<tr class="odd">
<td>Cricket</td><td>11</
td><td></td>
</tr>
<tr class="even">
<td>Lacrosse</td><td>10</
td><td></td>
</tr>
<caption>Popular Team Sports</
caption>
</table>
</body>
</html>
191
Chapter 6: Tables
<style type="text/css">
table
{
border: 2px solid #0000AA;
}
This puts a border around the table, but not surrounding each cell. To put
borders around each cell, add selector elements th and td in the style tag
with a border attribute of its own. Refer to the code below to see how this
can be accomplished:
<style type="text/css">
table
{
border: 2px solid #0000AA;
}
th, td
{
border: 1px solid #0000AA;
}
The code line shown in bold will create the border that surrounds each
cell. Notice, however, that the border style displayed shows a double-lined
border. This can be modified and collapsed by including the bordercollapse attribute in the table styles. This is how the code should
progress by now:
6.2 Styling Tables with CSS
192
<style type="text/css">
table
{
border: 2px solid #0000AA;
border-collapse: collapse;
}
th, td
{
border: 1px solid #0000AA;
}
<tr class="odd">
or
<tr class="even">
The code should now be:
<style type="text/css">
table
{
border: 2px solid #0000AA;
border-collapse: collapse;
}
th, td
{
border: 1px solid #0000AA;
}
193
th
{
background-color: black;
color: white;
}
Chapter 6: Tables
CSS class style may now be included. Begin a class with a dot so that
CSS will not interpret it as a selector. Start with either the .odd or .even
class. Here is how the code should look:
<style type="text/css">
table
{
border: 2px solid #0000AA;
border-collapse: collapse;
}
th, td
{
border: 1px solid #0000AA;
}
th
{
background-color: black;
color: white;
}
.odd
{
background-color: black;
color: white;
}
.even
{
background-color: rgb(215,215,215)
}
The font-type can also be set for the entire table or row. We can change
the table header and table data fonts to display different fonts using
font-family: font name attribute. We can also change the font size
using the font-size: font size value attribute. Should you want to
align the texts, the attribute to use is text-align: alignment value.
Refer to the code below for a clearer grasp on the idea:
194
<style type="text/css">
table
{
border: 2px solid #0000AA;
border-collapse: collapse;
}
th, td
{
border: 1px solid #0000AA;
font-family: arial;
font-size: .8em;
text-align: left;
}
th
{
background-color: black;
color: white;
}
.odd
{
background-color: black;
color: white;
}
.even
{
background-color:rgb(215,215,215)
}
Another styling you can do is setting the width of a table. There are
different ways to change the width; one is by setting the table by means
of pixel measure. The attribute to use is width: pixel size value;
next is by setting it to a percentage of the browser window, syntax is
width: number%. This must be placed inside the table style selector.
Remember that with percentage setting selected the table will always
adjust to the size of the browser window. Refer to the following code to
see exactly how width attribute is included:
195
Chapter 6: Tables
<style type="text/css">
table
{
border: 2px solid #0000AA;
border-collapse: collapse;
width: 400px;
}
th, td
{
border: 1px solid #0000AA;
font-family: arial;
font-size: .8em;
text-align: left;
}
th
{
background-color: black;
color: white;
}
.odd
{
background-color: black;
color: white;
}
.even
{
background-color:rgb(215,215,215)
color:
}
Styling your caption is also easy and enhances the look of the table. To
change the placement of your caption, the caption-side attribute is
used. Fonts can be changed using the font-family attribute and the size,
with font-size attribute. Background color can also be changed to set the
caption apart from the rest of the table. By default, captions dont have
6.2 Styling Tables with CSS
196
Chapter 6: Tables
{
background-color:
rgb(215,215,215);
}
.even
{
background-color: rgb(245, 245,
245);
}
caption
{
font-family: arial;
font-size: 1.3em;
caption-side: top;
}
</style>
</head>
<body>
<table>
<tr>
<th>Player Name</th><th>Player
Position</th><th>Batting
Average</th>
</tr>
<tr class="odd">
<td>Todd Smith</td><td
colspan="2">Pitcher</td>
</tr>
<tr class="even">
<td>Fred Thomas</
td><td>Catcher</td><td>.300</td>
</tr>
<tr class="odd">
<td>Jamal Williams</td><td>Left
Field</td><td>.312</td>
</tr>
6.2 Styling Tables with CSS
198
<tr class="even">
<td>Tommy Thomas</td><td>Center
Field</td><td>.256</td>
</tr>
<tr class="odd">
<td>Phillip Zachary</td><td>1st
Base</td><td>.309</td>
</tr>
<tr class="even">
<td>Marc Patterson</td><td>2nd
Base</td><td>.415</td>
</tr>
<tr class="odd">
<td>Bryan Dill</td><td>3rd
Base</td><td>.387</td>
</tr>
<tr class="even">
<td>Nick Terry</td><td>Right
Field</td><td>.289</td>
</tr>
<caption>Westport Little League
All-Stars</caption>
</table>
</body>
</html>
199
Chapter 6: Tables
This is how the table will look when viewed in the browser:
FIGURE 6 - 3
200
201
Chapter 6: Tables
No. Name
Pos.
Age
Birth Place
Salary
38
Luis Ayala
RP
33
Los Mochis,
Mexico
$650,000
66
Andrew
Brackman
RP
25
Cincinnati, OH
N/A
34
A.J. Burnett
SP
34
North Little
Rock, AR
$16,500,000
40
Bartolo Colon
SP
38
Altamira,
Dominican
Republic
$900,000
36
Freddy Garcia
SP
35
Caracas,
Venezuela
$1,500,000
65
Phil Hughes
SP
25
Mission Viejo,
CA
$2,700,000
70
George Kontos
RP
26
Lincolnwood, IL
N/A
22
Aaron Laffey
RP
26
Cumberland,
MD
$431,600
48
Boone Logan
RP
27
64
Hector Noesi
RP
24
Esperanza,
Dominican
Republic
N/A
47
Ivan Nova
SP
24
San Cristobal,
Dominican
Republic
$432,900
41
Scott Proctor
RP
34
Stuart, FL
N/A
42
Bob Rivera
RP
41
Panama City,
Panama
$14,911,701
30
David
Robertson
RP
26
Birmingham, AL $460,450
52
CC Sabathia
SP
31
Vallejo, CA
$24,285,714
29
Rafael Soriano RP
31
San Jose,
Dominican
Republic
$9,000,000
61
Raul Valdes
RP
33
Havana, Cuba
N/A
53
Cory Wade
RP
28
Indianapolis, IN
N/A
TABLE 6 - 1
202
Lab Solution
Chapter 6: Tables
{
}
font-family: verdana;
text-align: center;
.even
{
background-color: blue;
color: white;
}
.odd
{
background-color: white;
color: blue;
}
</style>
</head>
<body>
<h1>New York Yankees Pitching
Staff</h1>
<table>
<tr>
<th>NO.</th><th>NAME</th><th>POS</
th><th>AGE</th><th>BIRTH PLACE</th>
<th>SALARY</th>
</tr>
<tr class="odd">
<td>38</td><td>Luis Ayala</
td> <td>RP</td> <td>33</td> <td>Los
Mochis,Mexico</td> <td>$650,000</td>
</tr>
<tr class="even">
<td>66</td> <td>Andrew
Brackman</td> <td>RP</td> <td>25</
td><td>Cincinnati,OH</td><td>N/A</td>
</tr>
<tr class="odd">
Final Lab Solutions
204
<td>34</td><td>A.J.
Burnett</td> <td>SP</td> <td>34</
td><td>North Little Rock, AZ</
td><td>$16,000,000</td>
</tr>
<tr class="even">
<td>40</td><td>Bartolo
Colon</td> <td>SP</td> <td>38</
td><td>Altamira, Dominican Republic</
td><td>$900,000</td>
</tr>
<tr class="odd">
<td>36</
td><td>Freddy Garcia</td> <td>SP</
td> <td>35</td><td>Caracas, Venezuela</
td><td>$1,500,000</td>
</tr>
<tr class="even">
<td>65</td><td>Phil
Hughes</td> <td>SP</td> <td>25</
td><td>Mission Viejo, CA</
td><td>$2,700,000</td>
</tr>
<tr class="odd">
<td>70</td><td>George
Kontos</td> <td>RP</td><td>26</
td><td>Lincolwood, IL</td><td>N/A</td>
</tr>
<tr class="even">
<td>22</td><td>Aaron
Lafey</td> <td>RP</td><td>26</
td><td>Cumberland, MD</td td>$431,000</td>
</tr>
<tr class="odd">
<td>48</td><td>Boone
Logan</td> <td>RP</td><td>27</td><td>San
Antonio, TX</td><td>$1,200,000</td>
</tr>
205
Chapter 6: Tables
<tr class="even">
<td>64</td><td>Hector
Noesi</td> <td>RP</td> <td>24</
td><td>Esperanza, Dominican Republic</
td><td>N/A</td>
</tr>
<tr class="odd">
<td>47</td><td>Ivan Nova</
td> <td>SP</td> <td>24</td> <td>San
Cristobal, Dominican Republic</td>
<td>$432,900</td>
</tr>
<tr class="even">
<td>41</td><td>Scott
Proctor</td><td>RP</td><td>34</
td><td>Stuart, FL</td><td>N/A</td>
</tr>
<tr class="odd">
<td>42</
td><td>Mariano Rivera</td> <td>RP</
td> <td>41</td><td>Panam City, Panama</
td><td>$14,911,701</td>
</tr>
<tr class="even">
<td>30</td><td>David
Robertson</td> <td>RP</td><td>26</
td><td>Birmingham, AL</td><td>$40,450</td>
</tr>
<tr class="odd">
<td>52</td><td>CC
Sabathia</td> <td>SP</td><td>31</
td><td>Vallejo, CA</td><td>$24,28,714</td>
</tr>
<tr class="even">
<td>29</td><td>Rafael
Soriano</td> <td>RP</td> <td>31</
td><td>San Jose, Dominican Republic</td>
<td>$9,000,000</td>
Final Lab Solutions
206
</tr>
<tr class="odd">
<td>61</td><td>Raul
Valdez</td> <td>RP</td><td>33</
td><td>Havana, Cuba</td><td>N/A</td>
</tr>
<tr class="even">
<td>53</td><td>Cory Wade</
td> <td>RP</td><td>28</td><td>Indianopolis,
IN</td><td>N/A</td>
</tr>
</table>
</body>
</html>
FIGURE 6 - 4
207
Chapter 6: Tables
Chapter 6 Summary
In Chapter 6 we discussed how tables are created in HTML, cited
their purpose and use, and introduced basic table design.
Use of CSS in designing tables was presented and our discussion
covered fonts, borders, class and caption styling.
The next chapter will discuss how to gather information from the
user via HTML textbox elements.
Definition
<table>
<tr>
<th>
<td>
rowspan="xxx"
colspan="xxx"
<caption>
class="xxx"
caption-side:
Position of caption.
TABLE 6 - 2
208
Chapter 7
HTML Forms
Chapter Objectives:
You will be able to create HTML forms.
You will be able to implement radio buttons and checkbox elements.
You will be able to use HTML5 form elements.
You will be able to create multi-select form elements.
<form>
To create forms you use the <form> tag. The <form> tag
has two attributes that are regularly used: action and
method. The action attribute tells the form where to send the information
to be processed. The information is usually sent to a PHP form or another
back end language. Since this course doesnt deal with PHP, you can
instead put # in the action attribute. Method, on the other hand,
defines how the data will be sent. The two values for sending data are get
and post. Get is less common and appends information the user types to
the URL as a query string and passes it to the page indicated in action.
Get is not a secure way of passing information because the information
appears in the URL. Post places all the information in an array and
passes it to the indicated page. It is considered more secure than Get. The
complete code for an open form tag is:
<form action="#" method="post">
To make the HTML form look neat and properly laid out, place it inside a
table, making each input element part of a table row. This technique will
lessen the use of break tags <br> and spaces in aligning the texts.
209
<input type="text"
Then give the tag a name. This is how it will be referred to when passed
to the server. In this case, our tag is named first. The tag will now look
like this:
210
/></td>
<td><input type="submit"
value="Send Info" />
</table>
</form>
</body>
</html>
This is how the output would look when viewed in the browser:
FIGURE 7 - 1
212
Lab Activity
Create an XHTML document and type the following code:
<td><input type="text"
name="last" id="last" /></td>
</tr>
<tr>
<tr>
<td>Middle Initial</td>
<td><input type="text"
name="middle" id="middle" /></td>
<td>Password:</td>
<td><input type="password"
name="password" id="password" /></td>
</tr>
<tr>
<td><input type="reset"
/></td>
<td><input type="submit"
value="Send Info" />
</table>
</form>
</body>
</html>
Your output should look like this when viewed in the browser:
FIGURE 7 - 2
214
Button Types
Radio
Checkbox
216
<tr>
<td>Password:</td>
<td><input type="password"
name="password" id="password" /></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input type="radio"
value="male" name="gender">Male
<input type="radio"
value="female" name="gender">Female
</td>
</tr>
<tr>
<td valign="top">Age
Range:</td>
<td>
<input type="radio"
value="0" name="age" />Under 18<br/>
<input type="radio"
value="1" name="age" />19-39<br/>
<input type="radio"
value="2" name="age" />40-59<br/>
<input type="radio"
value="3" name="age" />Over 60<br/>
</td>
</tr>
<tr>
<td valign="top">Bands you
like:</td>
<td>
<input type="checkbox"
value="journey" name="bands"/>Journey<br/>
<input type="checkbox"
value="reo" name="bands"/>REO
Speedwagon<br/>
<input type="checkbox"
217
value="survivor" name="bands"/>Survivor<br/>
<input type="checkbox"
value="heart" name="bands"/>Heart<br/>
</td>
</tr>
<tr>
<td><input type="reset" /></
td>
<td><input type="submit"
value="Send Info" />
</table>
</form>
</body>
</html>
This is how the form will look when viewed in a browser. For gender,
the user can only select male or female, as well as only one age range.
However, for the band they can select as many bands as they like.
FIGURE 7 - 3
218
Lab Activity
Type the following code and view your output.
<title>Creating Form</title>
</head>
<body>
<form action="#" method="post">
<table>
<tr>
<td>First name:</td>
<td><input type="text"
name="first" id="first"/></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text"
name="last" id="last"/></td>
</tr>
<tr>
<tr>
<td>Middle Initial:</td>
<td><input type="middle"
name="middle" id="middle"
/></td>
</tr>
<td>Password:</td>
<td><input type="password"
name="password"
id="password" /></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input type="radio"
value="male" name="gender">Male
<input type="radio"
value="female"
name="gender">Female
</td>
</tr>
<tr>
7.2 Creating Radio Button and Checkbox Elements
220
like:</td>
<td>
<input type="checkbox"
value="journey"
name="bands"/>Journey<br/>
<input type="checkbox"
value="reo" name="bands"/>REO
Speedwagon<br/>
<input type="checkbox"
value="survivor"
name="bands"/>Survivor<br/>
</td>
</tr>
<tr>
<td><input type="reset" /></td>
<td><input type="submit"
value="Send Info" /></td>
</tr>
</table>
</form>
</body>
</html>
Your output should look like this when viewed in a browser:
FIGURE 7 - 4
221
<!DOCTYPE html>
To work on forms with HTML5, two form attributes are needed, action
and method:
FIGURE 7 - 5
222
The type=date element, on the other hand, brings out a widget type of
calendar where the user may select a specific date and year. Its tag is:
FIGURE 7 - 6
FIGURE 7 - 7
Two elements that are unique and are mostly implemented on mobile
browsers that make use of a touch screen are type=email and
type=tel. Type email utilizes a textbox where the @ sign is affixed;
whereas the type telephone might have a telephone pad in it. These are
optimized to ease input for the user. The tags are:
FIGURE 7 - 8
Code Listing: HTML5 Form Elements
<!DOCTYPE html>
<html>
<head>
<title>Html 5 Form Element</title>
</head>
<body>
<form action="#" method="post">
Color:
<input type="color" name="color"/>
<br/>Date of Birth:
<input type="date" name="dob" />
<br/>Time of Appointment:
<input type="time"
name="timeOfAppointment"/>
<br/>Email:
<input type="email" name="email"/>
7.3 New HTML5 Form Elements
224
/>
<br/>Telephone:
<input type="tel" name="telephone"
<br/>Age:
<input type="number" name="age"
min="0" max="115"/>
</form>
</body>
</html>
This is how the form appears on some browsers. Keep in mind that not
all browsers support HTML5 forms yet. Email and telephone forms arent
changed because this is not a mobile browser. On mobile browsers, the
forms would bring up an optimized keyboard for mobile devices.
FIGURE 7 - 9
225
226
<select>
228
This is how our menu form will appear in the browser. Notice how all
seven rows appear because we set the size attribute to 7.
FIGURE 7 - 10
Lab Activity
Modify the following code so that the size is set to only display three
choices, while increasing the number of overall choices to 10 by adding
three more food varieties.
230
</select>
</form>
</body>
</html>
Your output should look like this when viewed in the browser:
FIGURE 7 - 11
231
Form Field
Type of Field
Text
Text
Text
Text
Text
Patient City
Text
Patient State
Drop-Down
Patient Zip
Text
Patient Age
Patient DOB
Patient Gender
232
</td>
</tr>
<tr>
<td>Street Address:</td>
<td>
<input type="text" name="address"
id="address" />
</td>
</tr>
<tr>
<td>City:</td>
<td>
<input type="text" name="city"
id="city" />
</td>
</tr>
<tr>
<td>State:</td>
<td>
<select>
<option>State 1</option>
<option>State 2</option>
<option>State 3</option>
<option>State 4</option>
<option>State 5</option>
<option>State 6</option>
<option>State 7</option>
</select>
</td>
</tr>
<tr>
<td>Zip:</td>
<td>
<input type="text" name="zip"
id="zip" />
</td>
</tr>
<tr>
Final Lab Solutions
234
<td>Age:</td>
<td>
<input type="number" name="city"
id="city" min="0"
max="115" />
</td>
</tr>
<tr>
<td>Date of Birth:</td>
<td>
<select name="dob">
<option value="jan">1</option>
<option value="feb">2</option>
<option value="mar">3</option>
<option value="apr">4</option>
<option value="may">5</option>
<option value="jun">6</option>
<option value="jul">7</option>
<option value="aug">8</option>
<option value="sep">9</option>
<option value="oct">10</
option>
<option value="nov">11</
option>
<option value="dec">12</
option>
</select> <select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
235
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input type="text" name="year"
id="year" />
</td>
<tr>
<td>Gender:</td>
<td>
<input type="radio" name="gender"
id="gender"
/>Male</input>
<input type="radio" name="gender"
id="gender"
/>Female</input>
</td>
</tr>
<tr>
<td>Health History:</td>
Final Lab Solutions
236
<td>
<input type="checkbox"
name="health" value="hattack"
/>Heart Attack</input><br/>
<input type="checkbox"
name="health" value="stroke"
/>Stroke</input><br/>
<input type="checkbox"
name="health" value="cancer"
/>Cancer</input><br/>
<input type="checkbox"
name="health" value="hyper"
/>Hypertension</input><br/>
<input type="checkbox"
name="health" value="depression"
/>Depression</input><br/>
<input type="checkbox"
name="health" value="copd"
/>COPD</input><br/>
Other<input type="text"
name="health" id="health"
/></input>
</td>
</tr>
<tr>
<td><input type="submit"
value="confirm" /></td>
<td><input type="reset"
value="start over" /></td>
</tr>
</table>
</form>
</body>
</html>
237
Chapter 7 Summary
In this chapter we learned how to use the HTML Forms. We were
able to differentiate their input types and the attributes that go
along with themtext, password, radio, checkbox, submit, reset,
and select. We were able to create a simple form and integrate
submit and reset buttons.
We were also able to use some of the new elements that are
included in the HTML5 format: Color, Date, Time, Number, Email,
and Tel. We have seen that not all browsers support these new
elements yet.
In the next chapter we will discuss how to use the CSS box model.
The CSS box model is a great way to lay out the content on your
website in a professional manner.
Definition
<form>
action=xxx
method=post
<input>
type=xxx
name=xxx
id=xxx
238
Chapter 8
Understanding the
CSS Box Model
Chapter Objectives:
You will be able to understand the CSS box model.
You will be able to implement the CSS box model.
You will be able to adjust margin, padding and borders.
FIGURE 8 - 1
Most of the elements of the CSS box model can be changed using CSS.
The next subchapter will show you how to do that.
240
Set the width of the box content to constrain the text; the style code is as
follows:
<title>Box Model</title>
<style type="text/css">
#box {
width: 375px;
}
</style>
241
Width: 375px
FIGURE 8 - 2
Now surround the box by a border; your code should now look like this:
<title>Box Model</title>
<style type="text/css">
#box {
width: 375px;
border: 1px;
}
</style>
242
Border: 1px
FIGURE 8 - 3
You will notice that there is space sitting between the edge of the browser
window and our box content. Let us set the margin to zero:
<title>Box Model</title>
<style type="text/css">
#box {
width: 375px;
border: 1px;
margin: 0px;
}
</style>
Setting the margin value to zero did not remove the margin, indicating
that the gap is not caused by our content but by the window. To resolve
this, what we need to do is include the body selector inside the style
element preceding the box selector id and set the margin to zero from
there. Our code should now be:
243
<title>Box Model</title>
<style type="text/css">
body {
margin: 0px;
}
#box {
width: 375px;
border: 1px black solid;
</style>
Margin: 0px
FIGURE 8 - 4
That removed the gap between the text box content and the browser.
To effectively see how margin settings behave, let us create a second
body of text by adding another logical division and assigning it the value
id=box2:
244
<div id="box">
(content)
</div>
<div id="box2">
(content)
</div>
Lets have a different border color for the second box to distinguish them
from one another. The CSS portion looks like this:
<style type="text/css">
body {
border: 0px;
}
#box {
width: 375px;
border: 1px black solid;
}
#box2{
width: 375px;
border: 1px red solid;
}
</style>
245
FIGURE 8 - 5
#box {
width: 375px;
border: 1px black solid;
margin-bottom: 10px;
margin-left: 10px;
}
246
Left-Margin: 10px
Bottom-Margin: 10px
FIGURE 8 - 6
(top)
(right)
(bottom)
(left)
This sets the top margin to 5px (margin: 5px); the right margin to 100px
(100px,); the bottom margin to 100px (100px,) and the left margin to 5px
(the last 5px entry in the row).
Take note that when using margin, the border margins you enter
are in the sequence: top-right-bottom-left following a clockwise
manner.
247
Left-Margin: 5px
Right-Margin: 100px
Top-Margin: 5px
Bottom-Margin: 100px
FIGURE 8 - 7
You can also have one value for margin which will give the same margin
for all sides, meaning:
margin: 10px;
is the same as:
margin: 10px, 10px, 10px, 10px;
which tells the browser that the top margin has 10px, the right side
margin has 10px, the bottom margin has 10px, and the left side margin
has 10px.
Setting the padding is somewhat similar to setting the margin, only that
while padding determines the space between the border and the content
itself, it also works the same way as margin.
8.2 Working with Margin, Padding and Borders
248
#box {
width: 375px;
border: 1px black solid;
margin-bottom 10px;
margin-left 10px;
padding: 10px;
}
Padding: 10px
FIGURE 8 - 8
Another look you can apply to your box is setting its background color.
Use the style attribute background-color to accomplish this. The
padding color takes on the background color of the box but the margin
takes on the background color of the page.
You also have the option to set the border to a variety of different styles.
You can alter the area of the border, its type and color.
249
<style type="text/css">
body {
border: 0px;
background-color: #aaaaaa;
}
#box {
width: 375px;
border: 1px black solid;
padding: 10px;
background-color: #cccccc;
}
Remember to take into consideration that the width of the padding,
margins and borders are independent from the defined width of the
division; meaning, the pixel sizes of each attribute is added to the total
width specified for the division, for our example the total size of division
is 375 + 10 + 10 + 1 + 1 = 397 pixels. So remember to finalize each
attribute and content of the division before setting a fixed value for the
width.
{
8.2 Working with Margin, Padding and Borders
250
solid;
#cccccc;
width: 375px;
border: 30px black
margin: 10px;
padding: 10px;
background-color:
}
</style>
</head>
<body>
<div id="box">
Cras euismod nunc non turpis
accumsan eu dictum nibh adipiscing.
Etiam et hendrerit massa. Morbi pretium,
magna sed consectetur hendrerit, dolor
dolor sagittis nibh, id ullamcorper leo
dui sit amet diam. Sed in urna sapien,
eget tempus elit. Fusce sed mattis urna.
Quisque ac ipsum sapien, quis aliquet
erat. Suspendisse est dolor, tincidunt eu
aliquam non, euismod quis sem. Praesent
orci mauris, accumsan ac pharetra faucibus,
vehicula eget dolor. Vivamus in velit at
enim dictum commodo sed quis dui. Nullam
interdum, odio at pellentesque sodales,
eros ligula convallis metus, ac malesuada
est mauris eu enim. Suspendisse potenti.
Integer volutpat sollicitudin dolor, ac
congue sem malesuada sed. In hac habitasse
platea dictumst. Ut eros augue, congue ac
consectetur eget, mattis ut velit.
</div>
</body>
</html>
251
This is how our styled box looks when viewed in the browser:
FIGURE 8 - 9
252
253
FIGURE 8 - 10
1.
2.
3.
4.
254
Padding: Border:
Margin:
Content
Color:
box 1:
10px
10px
default
box 2:
5px
10px
default
box 3:
2px
10px
default
TABLE 8 - 1
255
Lab Solution
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Strict//EN" "http://www.w3.org/TR/
xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en">
<head>
<title>Box Model</title>
<style type="text/css">
body
{
margin: 10px;
background-color:
#00ffff;
}
#box1
{
width: 365px;
border: 15px green
solid;
margin: 10px;
padding: 10px;
background-color:
#C0C0C0;
}
#box2
groove;
width: 370px;
border: 15px teal
margin: 10px;
padding: 5px;
background-color:
#008080;
}
#box3
{
Final Lab Solutions
256
dotted;
#0000ff;
width: 373px;
border: 15px aqua
margin: 10px;
padding: 2px;
background-color:
}
</style>
</head>
<body>
<div id="box1">
Cras euismod nunc non turpis
accumsan eu dictum nibh adipiscing. Etiam
et hendrerit massa. Morbi pretium, magna
sed consectetur hendrerit, dolor dolor
sagittis nibh, id ullamcorper leo dui sit
amet diam. Sed in urna sapien, eget tempus
elit. Fusce sed mattis urna. Quisque ac
ipsum sapien, quis aliquet erat.
</div>
<div id="box2">
Cras euismod nunc non turpis
accumsan eu dictum nibh adipiscing. Etiam
et hendrerit massa. Morbi pretium, magna
sed consectetur hendrerit, dolor dolor
sagittis nibh, id ullamcorper leo dui sit
amet diam. Sed in urna sapien, eget tempus
elit. Fusce sed mattis urna. Quisque ac
ipsum sapien, quis aliquet erat.
</div>
<div id="box3">
Cras euismod nunc non turpis
accumsan eu dictum nibh adipiscing. Etiam
et hendrerit massa. Morbi pretium, magna
sed consectetur hendrerit, dolor dolor
sagittis nibh, id ullamcorper leo dui sit
amet diam. Sed in urna sapien, eget tempus
257
This is how the output will look when viewed in the browser:
FIGURE 8 - 11
258
Chapter 8 Summary
In this chapter we discussed how the CSS box model is
implemented. The CSS box model is used to create professional
looking websites. You learned how to work with margin, padding
and border elements to achieve the right look for your website.
The next and final chapter will discuss the differences and uses of
inline versus block elements; how the float and clear attributes are
used and how to create a navigation bar using CSS.
Definition
Margin
Content box
Border
Padding
259
260
Chapter 9
font-family: arial;
font-size: .8em;
width: 400px;
border:1px solid black;
}
</style>
</head>
<body>
<div id="div1">
Cras euismod nunc non turpis
accumsan eu dictum nibh adipiscing. Etiam
et hendrerit massa. Morbi pretium, magna
sed consectetur hendrerit, dolor dolor
sagittis nibh, id ullamcorper leo dui sit
amet diam. Sed in urna sapien, eget tempus
elit. Fusce sed mattis urna. Quisque ac
ipsum sapien, quis aliquet erat.
</div>
<div id="div2">
Cras euismod nunc non turpis
accumsan eu dictum nibh <span>adipiscing.
Etiam et hendrerit massa. Morbi pretium, </
span>magna sed consectetur hendrerit, dolor
dolor sagittis nibh, <p>id ullamcorper leo
dui sit amet diam. Sed in urna sapien, eget
tempus elit. Fusce sed mattis urna. Quisque
ac ipsum sapien, quis aliquet erat.</p>
</div>
</body>
</html>
262
The above code will display the following output when viewed in the
browser:
Div 1
Div 2
FIGURE 9 - 1
#div1
{
}
{
}
display: inline;
display: inline;
span
263
display: block;
Inline
Block
FIGURE 9 - 2
There you see the difference between block level and inline level
positioning. Block versus inline is fairly easy to figure out and manipulate
using CSS.
Now let us take a look at some different properties. We now know that
we can set the width of an element through the width: value attribute.
We can also set the height of an element via the attribute height: value.
If the set height does not accommodate the whole text content, the excess
or text overflow can be manipulated with the attribute overflow: option.
Some options for overflow are: auto, scroll, visible and hidden.
264
FIGURE 9 - 3
FIGURE 9 - 4
265
FIGURE 9 - 5
Hidden will not show the overflowing content, only the text or
content that fits inside the block:
FIGURE 9 - 6
266
FIGURE 9 - 7
Absolute:
FIGURE 9 - 8
267
/*
#div1
{
}
p
}
span{
height: 100px;
overflow: auto;
position: absolute;
top: 100px;
left: 100px;
}
display: inline;
display: inline;
268
display: block;
*/
</style>
</head>
<body>
<div id="div1">
Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Vivamus
elementum dictum lacinia. Ut dictum porta
feugiat. Nunc laoreet interdum justo, ac
tempor libero porttitor feugiat. Vestibulum
ultrices facilisis porta. Donec consectetur
hendrerit pharetra. Donec molestie nisl
sed tellus dignissim gravida aliquam nulla
hendrerit. Phasellus sed ante at neque
faucibus eleifend. Nulla lobortis ante
vitae metus fermentum luctus. Suspendisse
luctus tincidunt tellus non blandit. Morbi
congue vestibulum lectus at imperdiet.
</div>
<!-<div id="div2">
Phasellus sit amet leo lacus. Cras
semper ullamcorper tortor ac tristique.
<span>Sed cursus sapien vitae libero
vulputate sollicitudin. Morbi purus
ligula, suscipit vel porta nec, ultrices
non purus.</span> Nunc a elit quis tortor
vehicula scelerisque. Ut hendrerit rutrum
mi, viverra facilisis elit semper at. Morbi
venenatis erat et ante porttitor tempus.
Aenean dolor nisi, vehicula eu feugiat
non, accumsan sed metus. Nunc suscipit
est id mauris fringilla aliquet. Nulla a
tristique massa. <p>Sed rutrum elementum
odio quis scelerisque. Fusce non nunc vitae
eros vehicula accumsan sed eget neque. Cum
269
270
text-align: center;
</style>
</head>
<body>
<div id="header">
<h1>This is a Simple, Example
Layout</h1>
</div>
<div id="div1">
Cras euismod nunc non turpis
accumsan eu dictum nibh adipiscing. Etiam
et hendrerit massa. Morbi pretium, magna
sed consectetur hendrerit, dolor dolor
sagittis nibh, id ullamcorper leo dui sit
amet diam. Sed in urna sapien, eget tempus
elit. Fusce sed mattis urna. Quisque ac
ipsum sapien, quis aliquet erat.
Cras euismod nunc non turpis
accumsan eu dictum nibh adipiscing. Etiam
et hendrerit massa. Morbi pretium, magna
sed consectetur hendrerit, dolor dolor
sagittis nibh, id ullamcorper leo dui sit
amet diam. Sed in urna sapien, eget tempus
elit. Fusce sed mattis urna. Quisque ac
ipsum sapien, quis aliquet erat.
Cras euismod nunc non turpis
accumsan eu dictum nibh adipiscing. Etiam
et hendrerit massa. Morbi pretium, magna
sed consectetur hendrerit, dolor dolor
sagittis nibh, id ullamcorper leo dui sit
amet diam. Sed in urna sapien, eget tempus
elit. Fusce sed mattis urna. Quisque ac
ipsum sapien, quis aliquet erat.
Cras euismod nunc non turpis
accumsan eu dictum nibh adipiscing. Etiam
et hendrerit massa. Morbi pretium, magna
sed consectetur hendrerit, dolor dolor
9.2 Float and Clear
272
274
This is what our code looks like using the float and clear attributes:
FIGURE 9 - 9
275
276
}
#footer
{
background-color: black;
color: white;
clear: both;
}
#footer p
{
font-size: .65em;
font-family: georgia;
text-align: center;
}
#header h1
{
font-family: arial;
font-size: 1.4em;
font-weight: bold;
text-align: center;
margin-top: 0px;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<h1>This is a Simple, Example,
Layout</h1>
</div>
<div id="div1">
<h2>This Is The Main Headline</h2>
<p>Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Vivamus
elementum dictum lacinia. Ut dictum porta
feugiat. Nunc laoreet interdum justo, ac
tempor libero porttitor feugiat. Vestibulum
ultrices facilisis porta. Donec consectetur
277
278
280
In this example, CSS has helped us create a professional layout for our
page. Observe how the header and footer divs were set apart through div1
and div2.
282
<html>
<head>
<title>
</title>
</head>
<body>
<ul>
<li><a
a></li>
<li><a
<li><a
<li><a
<li><a
<li><a
</ul>
283
href="url"LearnToProgram</
href="url">Udemy</a></li>
href="url">UCONN</a></li>
href="url">CNN</a></li>
href="url">CNET</a></li>
href="url">TWiT</a></li>
This is how the list will look when viewed in the browser:
FIGURE 9 - 10
This is an unordered list of example websites. You may use any site
you want to for this application exercise. Using CSS, let us turn the
unordered list into an actual navigation bar.
First, we place the CSS declaration in the head. Next, remove the bullets
and then the underlines, including the color change for visited and
unvisited links.
ul
{
list-style-type: none;
}
284
FIGURE 9 - 11
Next we want to eliminate the underline of the links and set the color
of the links to black. To do that, change the text-decoration attribute to
none. Following is the code to implement the CSS style changes:
li a:link, li a:visited
{
text-decoration: none;
color: #666666;
}
285
FIGURE 9 - 12
li {
display: block;
}
286
FIGURE 9 - 13
li {
display: inline;
}
287
FIGURE 9 - 14
li {
}
display: block;
padding-top: 15px;
padding-bottom: 15px;
width: 170px;
margin: -2px;
This will now change the distances between each list item vertically:
FIGURE 9 - 15
Now you can set the background color of the list items to differentiate the
navigation bar from the rest of the page. In our example we set our list
background to yellow. To do the same, follow the codes below:
288
li {
}
display: inline;
padding-top: 15px;
padding-bottom: 15px;
width: 150px;
margin: -2px;
background-color: yellow;
The list item will now look like this when viewed on the browser:
FIGURE 9 - 16
There are a couple of small changes we are going to make to our design.
Lets change the font to Georgia, the color to light brown, the font-weight
to bold and the font-size to 120% of the default font size.
289
li a:link, li a:visited
{
text-decoration: none;
color: #666666;
font-family: Georgia, times;
font-weight: bold;
font-size: 1.2em;
}
This is how the list items will look when viewed in the browser:
FIGURE 9 - 17
If you want to create a small rollover effect so that the user knows when
the cursor is on the specific link, you will once again work with a pseudoelement. This pseudo-element is:
290
li:hover
{
}
background-color: orange;
FIGURE 9 - 18
This indicates when the cursor is hovering over the specific list item.
This effect is achieved by changing the background color by means of the
pseudo-element. In the above example, when the user hovers the cursor
over any link list item, the background color changes to orange.
Following is the code listing for creating a navigation bar. Notice how the
padding is set and the width is accommodating all list items.
291
292
{
background-color: orange;
}
</style>
</head>
<body>
<ul>
<li><a href="http://www.
learntoprogram.tv">LearnToProgram</a></li>
<li><a href="http://www.udemy.
com">Udemy</a></li>
<li><a href="http://www.uconn.
edu">UCONN</a></li>
<li><a href="http://www.cnn.
com">CNN</a></li>
<li><a href="http://www.cnet.
com">CNET</a></li>
<li><a href="http://www.twit.
tv">TWiT</a></li>
</ul>
</body>
</html>
This is how the horizontal navigation bar will end up looking. With a few
tweaks, you create an entirely different looking, but similarly functional,
navigation bar. Observe how links display a orange background when
hovered over.
FIGURE 9 - 19
293
294
FIGURE 9 - 20
295
Lab Solution
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
>
<html lang="en">
<head>
<title>Lab 9: Page Layout</title>
</head>
<style>
#container
{
width: 960px;
margin: 0px auto;
height: 400px;
}
#div1
{
font-family: arial;
font-size: 1em;
color: white;
height: 80px;
border: none;
background-color: #000000;
text-align: center;
margin-top: -21px;
padding-bottom: 75px;
}
#div2
{
font-family: times new
roman;
font-size: 1.2em;
padding-left: 50px;
padding-right: 50px;
Final Lab Solutions
296
}
#div3
{
}
#div4
{
}
#div5
{
padding-top: 25px;
padding-bottom: 10px;
color: white;
height: 25px;
border: none;
background-color: #0000FF;
background-color: #aaaaaa;
width: 280px;
font-size: 0.6em;
padding-left: 10px;
padding-right: 10px;
text-wrap: normal;
height: auto;
float: left;
background-color: #dddddd;
width: 620px;
font-size: 0.9em;
padding-left: 20px;
padding-right: 20px;
text-wrap: normal;
height: 1122px;
float: right;
padding-bottom: 10px;
clear: both;
background-color: black;
color: white;
padding-left: 20px;
}
#div5 a:link
297
ul
{
color: white;
text-decoration: none;
}
list-style-type: none;
margin: 0px;
padding: 0px;
}
li a:link, li a:visited
{
text-decoration: none;
color: #FFFFFF;
font: georgia, times;
font-weight: bold;
font-size: .75em;
width: 960px;
}
li
{
display: inline;
padding-top: 10px;
padding-bottom: 8px;
padding-left: 50.05px;
padding-right: 50.05px;
width: 960px;
margin: -2px auto;
}
li:hover
{
text-decoration: underline;
}
html
{
text-transform: uppercase;
}
Final Lab Solutions
298
</style>
<body>
<div id="container">
<div id="div1">
<h1>PAGE LAYOUT LAB EXERCISE</h1>
</div>
<div id="div2">
<ul>
<li><a href="#">NEWS</a></li>
<li><a href="#">WEATHER</a></li>
<li><a href="#">TECHNOLOGY</a></
li>
<li><a href="#">LOCAL</a></li>
<li><a href="#">SHOPPING</a></
li>
</ul>
</div>
<div id="div3">
<h2>KEEPING UP</h2>
<p>Lorem ipsum dolor sit amet,
consectetur adipiscing elit. In quis sapien
metus. Etiam libero arcu, ornare venenatis
lobortis sed, faucibus sit amet quam. Proin
augue ante, blandit nec blandit aliquet,
egestas mattis urna. Sed libero erat,
pellentesque vel lacinia sed, semper eu
massa. Mauris id ante nisi, ut ornare velit.
Nulla quis diam quis dolor tempor molestie
a sit amet ligula. Ut vitae mollis eros.
Cras blandit eros sit amet ligula lacinia id
semper dui imperdiet. Etiam vel orci non sem
fringilla euismod at sit amet sem. Nullam
scelerisque nisl nec lorem mollis dignissim.
Sed varius lectus et augue elementum sed
venenatis dui scelerisque. Proin iaculis
odio a est facilisis id pellentesque odio
semper. Donec feugiat sodales dolor, id
pharetra tellus dapibus id.</p>
299
300
302
304
Chapter 9 Summary
In this chapter we discussed inline vs. block elements and how they
are used. You also learned how to use the float and clear attributes
in order to properly lay out the content in the CSS box model.
We also discussed how to create a CSS navigation bar. CSS allows
you to create a flexible, functional and good-looking navigation bar
compared to those created using HTML.
305
306
307
Answer Key
Answer Key
Chapter 1.1 Web Development Technology
1. What coding technology implements the design of a web page?
Answer: a. HTML
Chapter 1.2 Hello World with HTML
1. What tag does every HTML document start with?
Answer: a. <HTML>
2. What section of HTML contains information about the website but
doesnt display on the page?
Answer: a. head
3. What tag contains content that will be used by search engines to index
your page?
Answer: c. <title>
Chapter 1.3 Basic Document Structure HTML 4.01/XHTML
1. In order to establish what version of HTML you are using in your
webpage, what declaration should you begin your webpage with?
Answer: c. <!DOCTYPE
2. When using XHMTL code, with which of these should you begin your
document?
Answer: d. An XML declaration
Chapter 1.4 Basic Document Structure HTML5
1. In HTML5, what declaration do you start the code with?
Answer: a. <!DOCTYPE html
2. What language component of web development specifies the design
elements of a web page?
Answer: b. CSS
3. Which is the element to declare you are using the HTML 4.01
standard?
308
Answer: a. <!DOCTYPE HTML PUBLIC-//W3C//DTD HTML
4.01//EN http://www.w3.org/TR//html4/strict.dtd>
4. What section of HTML contains information about the website but
doesnt display on the page?
Answer: <head>
5. What tag is used to create text that could be indexed by search engines
and saved as titles to bookmarks?
Answer: <title>
6. In order to establish what version of HTML you are using in your
webpage, what element should you begin you webpage with?
Answer: <!DOCTYPE>
7. What website do you need to go in order to validate your HTML code?
Answer: c. validator.w3.org
8. If you are using the XHTML standard, what element should appear
first in your code?
Answer: d. An XML declaration
9. In HTML5, what element should begin your code?
Answer: <!DOCTYPE html>
10. Where are the comments visible?
Answer: d. only in the code
11. Which symbol is used to begin HTML comment elements?
Answer: <!-12. Where do metatags allow you to put information about your webpage?
Answer: b. Within the title of the document
13. Which metatag often will appear as a description in search engine
results?
Answer: <meta name= description >
Chapter 1.5 Using Comments in HTML
1. Where are comments visible?
Answer: d. Only in the code listing
309
Answer Key
2. What symbol is used to begin HTML comments?
Answer: <!-Chapter 1.6 HTML Head Elements
1. Where do metatags allow you to put information about your web page?
Answer: Within the head of the document
2. Which metatag will often appear as a description in search engine
results?
Answer: <meta name= description>
Chapter 2.1 Text Markup
1. What does the <br> tag do?
Answer: a. It creates a line break
2. What tag creates a second level header?
Answer: <h2>
3. What tag would make text appear bold according to the default style
sheet?
Answer: <strong>
Chapter 2.2 Div and Span Tags
1. What does the div tag stand for?
Answer: a. Logical division
2. What does a span tag accomplish?
Answer: b. It sections off a segment of text for the CSS to format
Chapter 2.3 HTML5 Text Markup Tags
1. What is semantic markup?
Answer: c. The idea that tags should be named based on their
functions rather than their presentation.
2. What markup tag would you generally use for the navigation of the
site?
Answer: b. <nav>
310
Answer Key
2. What tag do you put a list item under?
Answer: d. <li>
3. What attriute and value would you use if you want your list to have
uppercase letters instead of numbers?
Answer: d. <ol type=A>
Chapter 3.2 Unordered Lists
1. What tag do unordered lists begin with?
Answer: a. <ul>
2. What attribute and value would you use if you wanted your list to have
hollow circles?
Answer: d. <ul type=circle>
3. What attribute and value would you use if you wanted your list to have
filled circles?
Answer: b. <ul type=disc>
4. What attribute and value would you useif you wanted your list to have
squares?
Answer: c. <ul type=square>
Chapter 3.3 CSS for Lists
1. What style in CSS should you use to determine the style of the list?
Answer: a. list-style-type:
2. If you wanted to create a custom button using a png file, what CSS
attribute will you need?
Answer: b. background-image; url (name.png)
Chapter 4.1 Creating External and Internal Links
1. Which of the following as the anchor tag?
Answer: a. <a>
2. If you want your link, www.famewebsite.com, in the text Link, which
anchor tag would be correct?
Answer: c. <a href= http://www.famewebsite.com>Link </a>
312
Answer Key
3. What CSS attribute should you add to your webpage to make sure you
dont have any borders around a picture with a link?
Answer: b. img { border: 0px; }
4. What attribute tag should you use to get the text to flow around your
image?
Answer: d.align=
Chapter 5.2 HTML5 Audio Embeds
1. What audio embedding change does HTML5 introduce when compared
with previous versions?
Answer: d. It no longer requires a third party plugin.
2. What attribute value do you use in your HTML to give the user control
over the audio?
Answer: a. <audio controls=controls>
3. What is the correct source tag if you want to embed an audio file
named play.wav?
Answer: c. <source src=play.wav type=audio/wav/>
4. Why is it important to supply several different formats of audio in
HTML5?
Answer: b. To ensure that whichever browser is used, it will find
a format it supports and play the audio.
Chapter 5.3 HTML5 Video Embeds
1. What tag is used in embedding video in HTML5?
Answer: b. <audio controls=controls>
2. What attribute do you use to set the size and width of a video file?
Answer: a. <video controls=controls width= height=>
3. How do you specify the video file source and its type when embedding
video in HTML5?
Answer: c. <source src=video file name.type type=video/type />
Chapter 6.1 Creating Tables with HTML
314
1. What are tables used for when CSS is a part of your HTML?
Answer: b. Displaying tabular information.
2. What tag do you use to start a table?
Answer: c. <table>
3. What tag is used to start table row?
Answer: a. <tr>
4. Which is the correct attribute syntax if you want to create a border for
your table?
Answer: d. <table Border=1>
5. What tag creates cells within tables?
Answer: c. <td>
Chapter 6.2 Styling Tables with CSS
1. What attribute do you use to put a border around the table in CSS?
Answer: a. table {border: enter attributes}
2. How would you create an attribute that would make the background of
the table a header black and the text white?
Answer: d. <table> { background-color=black; color=white; }
3. How do you set the width of the table to be a constant 70 percent of the
browser window in CSS?
Answer: d. { table width: 70%}
Chapter 7.1 Creating Text Form Elements
1. Why are forms important to have on your website?
Answer: c. Forms allow users to input information in the
website for processing, especially if the website deals with exchange of
information.
2. What form tag attribute is required for forms to work?
Answer: a. <form action=# method=>
3. How do you create a text form that changes the input to dots and
asterisks?
Answer: d. <input type=password
315
Answer Key
Chapter 7.2 Creating Radio Button and Checkbox Elements
1. If a radio button has to be created for a yes answer as part of the
group Question, what would be the correct tag?
Answer:b. <input type=radio value=yes name=Question
\>Yes
2. What tag is used to create a checkbox?
Answer: b. <input type=checkbox
3. What is the difference between the radio buttons and checkboxes in
HTML?
Answer: c. Checkboxes allow you to select multiple items and
radio buttons only one.
Chapter 7.3 New HTML5 Form Elements
1. What does the <input type=color element create?
Answer: d. It creates a box that allows the user to select a color.
2. What does the <input type=date element create?
Answer: a. It gives the user an input box where they can input
the date or open a calendar to select the date.
3. What do the min and max attributes change in an input form?
Answer: a. They allow you to create minimum and maximum
number data entries.
Chapter 7.4 Creating Multi-Select Elements
1. What do you use to create your drop-down box?
Answer: d. <select>
2. If you wanted to make 5 items appear on the drop-down list at the
same time, what element what you use?
Answer: b. size=
3. What element would you use to allow the user to input multiple items
on the list?
Answer: c. multiple=multiple
316
317
Answer Key
Answer: c. It stays within the line and adjusts to the width of the
browser.
2. If you wanted to create a sentence or sentences within inline text that
stayed within its own block, what tag would you use and what attribute
would you give it?
Answer: a. The <p> tag and the inline attribute
3. What attribute deals with how content overflow is handed within a box
and creates a scroll bar if needed?
Answer: d. overflow:auto
4. What does the position: absolute attribute accomplish?
Answer: a. The div becomes part of the page flow and moves with
the content surrounding it.
Chapter 9.2 Float and Clear
1. How does a container div alter a layout?
Answer: a. It sets the attributes for divs that have not beeen set
2. What attribute do you use to center the div on the page?
Answer: a. margin: 0 auto;
3. What attribute would you use to line divs up next to one another?
Answer: c. float
Chapter 9.3 Creating a CSS Navigation Bar
1. How do you start your navigation bar in HTML?
Answer: c. by creating an unordered list item full of links
2. What attribute would you use to take the bullets out of the list?
Answer: a. list-style-type: none;
318
319
Course Review
Hopefully this course has helped you achieve your objectives for
learning HTML and CSS. The primary objective of this course
was to help you start off your web development skills so that you
can produce your own websites. After reading this course and
performing the labs, you should be able to create websites that are
both functional and stylish.
If you wish to consider learning web development, there are many
different options that you can pursue. Javascript is a terrific web
development language and is great for creating dynamic web
applications. PHP is another great language to learn because it
helps you manage data on your website.
Finally, if you are interested in a website that can change content
without any page refresh, you might want to consider AJAX. This
technology, which stands for Asynchronous Javascript and XML,
will allow you to create a smooth website that functions similarly
to a desktop application.
By completing this course you have taken the first step into a much
wider world of web development. Whether you choose to continue
on or not, the skills you have developed will hopefully help you
create the exact website you are looking for.
320
Explanation
<a> </a>
Anchor or link
<abbr> </abbr>
Abbreviation
<address> </address>
<area >
<article></article>
Article
<aside></aside>
Tangential content
<audio></audio>
Audio stream
<b> </b>
Bold
<base>
<bdo> </bdo>
Bi-directional algorithm
<blockquote> </
blockquote>
Long quotation
<body> </body>
<br>
Line break
<button> </button>
<canvas></canvas>
<!-- -->
Comment
321
Tag
Explanation
<caption> </caption>
Table caption
<cite> </cite>
Citation
<code> </code>
Code reference
<col>
Table column
<colgroup> </colgroup>
<command>
<!doctype>
<datagrid></datagrid>
Data grid
<datalist></datalist>
<dd> </dd>
<del> </del>
Deleted text
<details></details>
<dfn> </dfn>
Definition
<dialog></dialog>
Conversation
<div> </div>
Logical division
<dl> </dl>
Description list
<dt> </dt>
<em> </em>
Emphasis
Appendix A - E
322
Tag
Explanation
<embed>
<fieldset> </fieldset>
<figure></figure>
<footer></footer>
<form> </form>
Form
<h1> </h1>
<h2> </h2>
<h3> </h3>
<h4> </h4>
<h5> </h5>
<h6> </h6>
<head> </head>
<header></header>
Header of a page
<hgroup></hgroup>
Heading group
<hr>
Horizontal rule
<html> </html>
<i> </i>
<iframe> </iframe>
Inline frame
323
Tag
Explanation
<img>
Image
<input>
<input type="button">
<input type="checkbox">
<input type="color">
Color input
<input type="date">
Date input
<input type="datetime">
<input type="datetimelocal">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
Number input
<input type="password">
<input type="radio">
<input type="range">
Appendix E - I
324
Tag
Explanation
<input type="reset">
<input type="search">
Search field
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
Time input
<input type="url">
URL input
<input type="week">
<ins> </ins>
Inserted text
<kbd> </kbd>
<keygen>
<label> </label>
Form label
<legend> </legend>
<li> </li>
List item
<link>
<map> </map>
<mark></mark>
<menu> </menu>
List of commands
325
Tag
Explanation
<meta>
<meter></meter>
Scalar gauge
<noscript> </noscript>
<object> </object>
Non-standard object
<ol> </ol>
<optgroup> </optgroup>
<option> </option>
<output></output>
<p> </p>
Paragraph
<param>
<pre> </pre>
Pre-formatted text
<progress></progress>
Progress indicator
<q> </q>
<rp></rp>
Ruby parenthesis
<rt></rt>
Ruby text
<ruby></ruby>
Ruby annotation
<s> </s>
Strikeout text
<samp> </samp>
Sample output
Appendix I - S
326
Tag
Explanation
<script> </script>
Scripts
<section></section>
Section of a page
<select> </select>
<small> </small>
<source>
Media source
<span> </span>
<strong> </strong>
Strong emphasis
<style> </style>
Style sheets
<sub> </sub>
Subscript
<summary> </summary>
<sup> </sup>
Superscript
<table> </table>
Table
<tbody> </tbody>
<td> </td>
Table cell
<textarea> </textarea>
<tfoot> </tfoot>
<th> </th>
<thead> </thead>
327
Tag
Explanation
<title> </title>
Title
<tr> </tr>
Table row
<ul> </ul>
<var> </var>
<video> </video>
Appendix S - Z
328
329