html foundations, pt 2

97
22-3375 Web Design I // Columbia College Chicago HTML Foundations, pt 2

Upload: shawn-calvert

Post on 28-Jan-2015

108 views

Category:

Education


3 download

DESCRIPTION

http://shawncalvert.com/webdesign-1 Web Design 1 Columbia College Chicago

TRANSCRIPT

Page 1: HTML Foundations, pt 2

22-3375 Web Design I // Columbia College Chicago

HTML Foundations, pt 2

Page 2: HTML Foundations, pt 2

Review

Page 3: HTML Foundations, pt 2

Anatomy of an Element

An HTML element includes both the HTML tag and everything between

the tag (the content).

<tag>Content</tag>

Page 4: HTML Foundations, pt 2

Anatomy of an Element

The element tag gives the content structure and meaning.

<tag>Content</tag>

Page 5: HTML Foundations, pt 2

Anatomy of an Element

Tags normally come in pairs. The first tag is the start tag, and the second

tag is the end tag.

<tag>Content</tag>

Page 6: HTML Foundations, pt 2

Anatomy of an Element

HTML has a defined set of tag names (also called keywords) that

the browser understands.

<h1>Main Headline</h1>

Page 7: HTML Foundations, pt 2

The essential element tags so far

PrimaryStructure html head body

Head Elements title meta

BodyElements p br h1 – h6

ul ol a img

Page 8: HTML Foundations, pt 2

Anatomy of an Element

Most elements can have attributes, which provides additional informatin

about the element.

<html lang=”en”></html>

Page 9: HTML Foundations, pt 2

Anatomy of an Element

Attributes always follow the sameformat: name=”value”. You can use

either single or double quotes.

<div class=”left-nav”></div>

Page 10: HTML Foundations, pt 2

The essential attributes so far

html <html lang=”en”></html>

meta <meta charset=”utf-8”>

link <link rel=”stylesheet” type-”text/css” href=”stylesheet/styles.css”>

img <img src=”images/image.jpg” alt=”Sam”>

a <a href=”http://colum.edu”>My school</a>

Page 11: HTML Foundations, pt 2
Page 12: HTML Foundations, pt 2
Page 13: HTML Foundations, pt 2

Properties

What are properties? While attributes provide additional information about a specific element’s content, every element type has a set of default properties that define how that element will be shown in the browser.

Page 14: HTML Foundations, pt 2

Properties

Element human

Properties name=”Liam”gender=”male” age=”5” !!

Page 15: HTML Foundations, pt 2

Block and Inline elements

One important default style applied to elements is whether they are block or inline. This is called their display property (we will talk about properties when we get to CSS).

A block element takes up the full width available to the element, and forces a line above and below. Examples include <p>, <div>, <ul>, <blockquote> and all headers.

block element

another element

another element

another element

Page 16: HTML Foundations, pt 2

Block and Inline elements

A inline element can be inserted within block elements or other inline elements and do no create additional space or line breaks. Examples include <img>, <em>, <strong>, <a>, and <span>.

<p></p>

<p>

<p></p>

<a></a> </p>

Page 17: HTML Foundations, pt 2

Class Exercise

!

Open ‘elements.html’ in bbedit and create tags around the

unstructured text.

Page 18: HTML Foundations, pt 2

Tags: Anchors (linking)

Page 19: HTML Foundations, pt 2

<a></a> STRUCTURE

The <a> element is an inline tag that works anywhere in the

body to create a hyperlink.

Page 20: HTML Foundations, pt 2

EXAMPLE

<a href="aboutme.html">About Me</a>

<a> tags are always used in pairs, wrapping the content you want to activate

as a link. If you use an absolute URL, it must start with “http://”.

<a href="http://www.colum.edu">My school</a>

Page 21: HTML Foundations, pt 2

Relative vs Absolute links

Whenever you link to a file with an ‘href‘ (hypertext reference ) or ‘src’ (source) attribute, you are providing the browser and address to the resource. That address can be relative or absolute.

root directory (www.mysite.com)

index.html

images

logo.png

report.pdf

stylesheet.css

!

Page 22: HTML Foundations, pt 2

Relative vs Absolute links

A relative link is relative to the resource’s location in its directory. It is like saying “the restaurant is 2 blocks away.” In the example below, if ‘logo.png‘ were linked from the homepage (index.html), the tag would be:

<img src=”images/logo.png”>

root directory (www.mysite.com)

index.html

images

logo.png

report.pdf

stylesheet.css

!

Page 23: HTML Foundations, pt 2

Relative vs Absolute links

An absolute link is the full address to the resource’s location in the entire web. It is like saying “the restaurant is at 222 West Grand, Chicago IL 60625.”

<img src=”http://www.mysite.com/images/logo.png”>

root directory (www.mysite.com)

index.html

images

logo.png

report.pdf

stylesheet.css

!

Page 24: HTML Foundations, pt 2

Directories

Page 25: HTML Foundations, pt 2
Page 26: HTML Foundations, pt 2

Room 902

<a href=” ”>

Page 27: HTML Foundations, pt 2

Room 902 Room 901 Room 903

9th Floor

9th Floor/Room 902/

Page 28: HTML Foundations, pt 2

Room 902 Room 901 Room 903

9th Floor

../Room 902/

Two dots in front of a forward slash means: “step up one directory.” In this example it says:

“step out of room 903 and then back into room 902, talk to “

Page 29: HTML Foundations, pt 2

Room 902 Room 901 Room 903

9th Floor8th Floor 10th Floor ++

WabashCampus

Mich AveCampus

Book & Paper Center ++

ColumbiaCollege

Universityof IL SAAIC ++

Page 30: HTML Foundations, pt 2

/Columbia College/Wabash Campus/9th Floor/Room 902/

http://Columbia College/Wabash Campus/9th Floor/Room 902/

Relative link to root A relative link (does not start with “http://”) with a slash at the beginning forces the link to start at the root of the website. This will only work on the server, not when you are working locally.

Absolute links Absolute links are typically used for linking to pages or files outside of your site’s directories.

Page 31: HTML Foundations, pt 2

The index file

When an absolute link is directed to a folder, the browser needs to know which file to open. By default, it looks for a file named “index” (the extension is not important, usually is it index.html, or index.php). This is why the homepage is always named “index”.

So, <a href=”http://www.mysite.com/”> and <a href=”http://www.mysite.com/index.html”> will open the same file.

root directory (www.mysite.com)

index.html

images

logo.png

Page 32: HTML Foundations, pt 2

Class Exercise

!

Open the folder ‘linking exercise” for a tutorial

Page 33: HTML Foundations, pt 2

Tables

Page 34: HTML Foundations, pt 2

What are tables? Tables are html elements that are used for presenting rows and columns of tabular data.

Tables are always created using three or more nested tags (at a minimum: table, tr, td)

For many years, designers used tables for layout, which is now done with CSS, except in certain scenarios (mainly for html emails).

Page 35: HTML Foundations, pt 2

table

thead

tfoot

tbody

tr

th

td

Page 36: HTML Foundations, pt 2

<table></table> STRUCTURE

The <table> tag defines and encloses the entire HTML table.

Page 37: HTML Foundations, pt 2

<thead></thead> STRUCTURE

The <thead> tag is used to group header content in an HTML table.

Page 38: HTML Foundations, pt 2

<tfoot></tfoot> STRUCTURE

The <tfoot> tag is used to group footer content in an HTML table.

Page 39: HTML Foundations, pt 2

<tbody></tbody> STRUCTURE

The <tbody> tag is used to group the body content in an HTML table.

Page 40: HTML Foundations, pt 2

<tr></tr> STRUCTURE

The <tr> tag defines a row in an HTML table.

Page 41: HTML Foundations, pt 2

<th></th>

These tags are the actual data cells:“table header” and “table data”.

Use <th> if the cell is inside <thead> tags.

<td></td>

Page 42: HTML Foundations, pt 2

EXAMPLE

from www.w3schools.com

Page 43: HTML Foundations, pt 2

<th colspan=”2”></th>

If your td or th element needs to span over another column, use the

colspan attribute.

<td colspan=”2”></td>

Page 44: HTML Foundations, pt 2

EXAMPLE

Every <tr> element in a table must contain the same number of cells, unless a ‘colspan’ element is used. In the example above, the first row has a cell that is using colspan=”2” to make a single cell take the space of two cells.

Page 45: HTML Foundations, pt 2

EXAMPLE

Every table must have table, tr and td (or th) tags. Marking up the header and body is good practice, but not essential.

Page 46: HTML Foundations, pt 2

Class Exercise

!

Open ‘table-exercises.html’ in bbedit and create two tables from

the un-marked-up content.

Page 47: HTML Foundations, pt 2

Forms

Page 48: HTML Foundations, pt 2
Page 49: HTML Foundations, pt 2

What is a form? HTML borrows the concept of a form to refer to different elements that allow you to collect information from visitors on your site.

Page 50: HTML Foundations, pt 2
Page 51: HTML Foundations, pt 2
Page 52: HTML Foundations, pt 2

How do HTML forms work? HTML form elements provide temporary storage for the information the user enters into the form. When the user clicks “submit,” the values are collected and sent to a server. The server processes the form data and sends back a new page (a response).

form server

Page 53: HTML Foundations, pt 2

Form Types

Page 54: HTML Foundations, pt 2

There are three basic types of form controls, for:

Adding Text

Making Choices

Submitting Forms

Uploading Files

Page 55: HTML Foundations, pt 2

Adding Text

Text Input

Password Input

Text Area

Page 56: HTML Foundations, pt 2

Making Choices

Radio Buttons

Checkboxes

Drop-downs

Page 57: HTML Foundations, pt 2

Submitting Forms

Submit Buttons

Image Buttons

Buttons

Page 58: HTML Foundations, pt 2

Uploading Files

File Upload

Page 59: HTML Foundations, pt 2

Form Syntax

Page 60: HTML Foundations, pt 2

The <form> tag is used to create an HTML form for user input.

<form></form>

Page 61: HTML Foundations, pt 2

The <form> tag contains the attributes that tell the browser how to handle the data when user hits ‘submit’. The essential, won’t-work-without-it, attribute is “action”. This is server address where the browser will send the data.

<form action=”http://www.mysite.com/process.php”>

</form>

Page 62: HTML Foundations, pt 2

<input> elements are used within a <form> element to declare input controls that allow users to input data.

<input> is an inline, self-closing tag.

An input field can vary in many ways, depending on the type attribute.

<form>

<input>

</form>

Page 63: HTML Foundations, pt 2

The <input> tag should always have, at a minimum, a type and name attribute.

The “type” attribute controls the form type (text, radio, dropdown, etc), and the “name” attribute is how you identify the data when it is sent to the server.

<form>

<input type=”text” name=”username”>

</form>

Page 64: HTML Foundations, pt 2

Input Attributes: type

You create the different type of form elements through the “type” attribute.

These include: text, password, radio, checkbox, select, file, submit, image, and hidden.

Page 65: HTML Foundations, pt 2

Input Attributes: type

For example:

<input type=”text”>

would create this:

Page 66: HTML Foundations, pt 2

Input Attributes: name

You then need to add a name so the data can be identified by the server:

<input type=”text” name=”username”>

!

Page 67: HTML Foundations, pt 2

Input Attributes: name

The data that is sent to the server is sent as a “name/value pair”. For example, if the user entered “Sarah” into the text box:

<input type=”text” name=”username”>

The server would receive:

username=”Sarah”

!

Page 68: HTML Foundations, pt 2

Class Exercise

!

Create a form for our tutorial:

Text input (name)

Dropdown (favorite color)

Radio (human or robot)

Text area (comment)

Submit

Page 69: HTML Foundations, pt 2

Adding Text: Examples

Text Input

Page 70: HTML Foundations, pt 2

Adding Text: Examples

Text Input You can add additional attributes to your text

inputs to control their width (size, in characters), and maxlength (in characthers). You can also control the width of the input field in your css (in pixels, % or ems).

Page 71: HTML Foundations, pt 2

Adding Text: Examples

Text Area Text areas are a bit different: they are not

contained in an <input> tag, and they require a closing tag (<textarea></textarea>.

Page 72: HTML Foundations, pt 2

Making Choices: Checkboxes

Checkboxes With checkboxes and radio buttons, the

“name” attribute creates the grouping between the options. The “value” attribute tells the server which option the user selected. add a “checked” value if you want an option to be preselected.

Page 73: HTML Foundations, pt 2

Making Choices: Radio Buttons

Radio Buttons Use a radio button when the user can only

select one option. Like checkboxes, add a “checked” value if you want an option to be preselected.

Page 74: HTML Foundations, pt 2

Making Choices: Dropdowns

Drop-downs Dropdowns are made up of two opening and

closing tags: <select> and <option>. Whatever option appears at the top is the default, unless you add a “selected=”selected” attribute to the option tag.

Page 75: HTML Foundations, pt 2

Uploading Files

File Upload

Page 76: HTML Foundations, pt 2

Submitting Forms: Submit

Submit A simple <input type=”submit”> is the easiest

way to add a submit button to your form. You can hook onto this element in css by using the pseudo selector input[type=submit].

Page 77: HTML Foundations, pt 2

Submitting Forms: Image

Image <input type=”image”> allows you to replace

the standard submit button with an image of a submit button. This method is not recommended.

Page 78: HTML Foundations, pt 2

Submitting Forms: Button

Button Inside a <button> element you can put

content, like text or images. This is the difference between this element and buttons created with the <input> element.

Page 79: HTML Foundations, pt 2

EXAMPLE

Page 80: HTML Foundations, pt 2

Form Labels

Page 81: HTML Foundations, pt 2

There are a few ways to add labels to your form elements. The simplest way is to just add unmarked up text with <br> elements.

<form>

Your Name<br> <input type=”text” name=”name”><br>

Your Email<br> <input type=”text” name=”email”><br>

<input type=”submit”>

</form>

Page 82: HTML Foundations, pt 2

Another way is to use the “label” element. It can wrap both the label and input, or stand outside of the input. You can style the label element in css.

If you use this method, you should add a “for” attribute to the label that matches the id of the form element (not required, but good for accessibility reasons).

<label for=”name”> Your Name<label><br>

<input type=”text” name=”name” id=”name”>

Page 83: HTML Foundations, pt 2

You can also wrap the entire element in the label tag. Both used of the label tag give your radio and checkboxes the added feature of making the entire field clickable.

<label>

Your Name<br> <input type=”text” name=”name”>

<label>

Page 84: HTML Foundations, pt 2

Form Design

Page 85: HTML Foundations, pt 2
Page 86: HTML Foundations, pt 2
Page 87: HTML Foundations, pt 2
Page 88: HTML Foundations, pt 2
Page 89: HTML Foundations, pt 2
Page 90: HTML Foundations, pt 2
Page 91: HTML Foundations, pt 2
Page 92: HTML Foundations, pt 2
Page 93: HTML Foundations, pt 2
Page 94: HTML Foundations, pt 2
Page 95: HTML Foundations, pt 2
Page 96: HTML Foundations, pt 2
Page 97: HTML Foundations, pt 2