43
HTML – Tables and Forms Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training www.nakov.com mvccourse.telerik.com

HTML – Tables and Forms

  • Upload
    hua

  • View
    77

  • Download
    3

Embed Size (px)

DESCRIPTION

mvccourse.telerik.com. HTML – Tables and Forms. Svetlin Nakov. Telerik Software Academy. academy.telerik.com. Manager Technical Training. www.nakov.com. Contents . HTML Tables Nested Tables Cells Width Cell Spacing and Padding Column and Row Span. Contents (2). HTML Forms - PowerPoint PPT Presentation

Citation preview

Page 1: HTML – Tables and Forms

HTML – Tables and Forms

Svetlin Nakov

Telerik Software Academyacademy.telerik.com

Manager Technical Trainingwww.nakov.com

mvccourse.telerik.com

Page 2: HTML – Tables and Forms

Contents 1. HTML Tables

Nested Tables Cells Width Cell Spacing and Padding Column and Row Span

2

Page 3: HTML – Tables and Forms

Contents (2)2. HTML Forms

Form Fields and Fieldsets Form Controls and Labels

Text field Text area Select Radio button Checkbox Button Image button

3

Page 4: HTML – Tables and Forms

HTML Tables

Page 5: HTML – Tables and Forms

HTML Tables Tables represent tabular data

A table consists of one or several rows

Each row has one or more columns Tables comprised of several core tags: <table></table>: begin / end the table<tr></tr>: create a table row<td></td>: create tabular data (cell)

Tables should not be used for layout. Use CSS floats and positioning styles instead

5

Page 6: HTML – Tables and Forms

HTML Tables (2) Start and end of a table

Start and end of a row

Start and end of a cell in a row

6

<table> ... </table>

<tr> ... </tr>

<td> ... </td>

Page 7: HTML – Tables and Forms

Simple HTML Tables – Example

7

<table cellspacing="0" cellpadding="5"> <tr> <td><img src="ppt.gif"></td> <td><a href="lecture1.ppt">Lecture 1</a></td> </tr> <tr> <td><img src="ppt.gif"></td> <td><a href="lecture2.ppt">Lecture 2</a></td> </tr> <tr> <td><img src="zip.gif"></td> <td><a href="lecture2-demos.zip"> Lecture 2 - Demos</a></td> </tr></table>

Page 8: HTML – Tables and Forms

<table cellspacing="0" cellpadding="5"> <tr> <td><img src="ppt.gif"></td> <td><a href="lecture1.ppt">Lecture 1</a></td> </tr> <tr> <td><img src="ppt.gif"></td> <td><a href="lecture2.ppt">Lecture 2</a></td> </tr> <tr> <td><img src="zip.gif"></td> <td><a href="lecture2-demos.zip"> Lecture 2 - Demos</a></td> </tr></table>

Simple HTML Tables – Example (2)

8

Page 9: HTML – Tables and Forms

Simple HTML TablesLive Demo

Page 10: HTML – Tables and Forms

Complete HTML Tables Table rows split into three semantic sections: header, body and footer <thead> denotes table header and

contains <th> elements, instead of <td> elements

<tbody> denotes collection of table rows that contain the very data

<tfoot> denotes table footer but comes BEFORE the <tbody> tag

<colgroup> and <col> define columns (most often used to set column widths)

10

Page 11: HTML – Tables and Forms

Complete HTML Table: Example

11

<table><colgroup> <col style="width:100px" /><col /></colgroup><thead> <tr><th>Column 1</th><th>Column 2</th></tr></thead><tfoot> <tr><td>Footer 1</td><td>Footer 2</td></tr></tfoot><tbody> <tr><td>Cell 1.1</td><td>Cell 1.2</td></tr> <tr><td>Cell 2.1</td><td>Cell 2.2</td></tr></tbody></table>

header

footer

Last comes the body (data)

th

columns

Page 12: HTML – Tables and Forms

<table><colgroup> <col style="width:200px" /><col /></colgroup><thead> <tr><th>Column 1</th><th>Column 2</th></tr></thead><tfoot> <tr><td>Footer 1</td><td>Footer 2</td></tr></tfoot><tbody> <tr><td>Cell 1.1</td><td>Cell 1.2</td></tr> <tr><td>Cell 2.1</td><td>Cell 2.2</td></tr></tbody></table>

Complete HTML Table:Example (2)

12

table-full.html

Although the footer is before the data in the

code, it is displayed last

By default, header text is bold and

centered.

Page 13: HTML – Tables and Forms

Nested Tables Table data “cells” (<td>) can contain

nested tables (tables within tables):

13

<table> <tr> <td>Contact:</td> <td> <table> <tr> <td>First Name</td> <td>Last Name</td> </tr> </table> </td> </tr></table>

nested-tables.html

Page 14: HTML – Tables and Forms

Nested TablesLive Demo

Page 15: HTML – Tables and Forms

cellpadding

Defines the empty space around the cell content

cellspacing

Defines the empty space between cells

Cell Spacing and Padding

Tables have two important attributes:

15

cell cell

cell cell

cell

cell

cell

cell

Page 16: HTML – Tables and Forms

Cell Spacing and Padding – Example

16

<html> <head><title>Table Cells</title></head> <body> <table cellspacing="15" cellpadding="0"> <tr><td>First</td> <td>Second</td></tr> </table> <br/> <table cellspacing="0" cellpadding="10"> <tr><td>First</td><td>Second</td></tr> </table> </body></html>

table-cells.html

Page 17: HTML – Tables and Forms

Cell Spacing and Padding – Example (2)

17

<html> <head><title>Table Cells</title></head> <body> <table cellspacing="15" cellpadding="0"> <tr><td>First</td> <td>Second</td></tr> </table> <br/> <table cellspacing="0" cellpadding="10"> <tr><td>First</td><td>Second</td></tr> </table> </body></html>

table-cells.html

Page 18: HTML – Tables and Forms

Table Cell Spacing and Cell PaddingLive Demo

Page 19: HTML – Tables and Forms

rowspan

Defines how many rows the cell occupies

colspan

Defines how many columns the cell occupies

Column and Row Span Table cells have two important attributes:

19

cell[1,1]

cell[1,2]

cell[2,1]

colspan="1"

colspan="1"

colspan="2"

cell[1,1]cell[1

,2]cell[2

,1]

rowspan="2"

rowspan="1"

rowspan="1"

Page 20: HTML – Tables and Forms

Column and Row Span – Example

20

<table cellspacing="0"> <tr class="1"><td>Cell[1,1]</td> <td colspan="2">Cell[2,1]</td></tr> <tr class=“2"><td>Cell[1,2]</td> <td rowspan="2">Cell[2,2]</td> <td>Cell[3,2]</td></tr> <tr class=“3"><td>Cell[1,3]</td> <td>Cell[2,3]</td></tr></table>

table-colspan-rowspan.html

Page 21: HTML – Tables and Forms

<table cellspacing="0"> <tr class="1"><td>Cell[1,1]</td> <td colspan="2">Cell[2,1]</td></tr> <tr class=“2"><td>Cell[1,2]</td> <td rowspan="2">Cell[2,2]</td> <td>Cell[3,2]</td></tr> <tr class=“3"><td>Cell[1,3]</td> <td>Cell[2,3]</td></tr></table>

Column and Row Span –Example (2)

21

table-colspan-rowspan.html

Cell[2,3]

Cell[1,3]

Cell[3,2]Cell[2,2

]

Cell[1,2]

Cell[2,1]Cell[1,1]

Page 22: HTML – Tables and Forms

HTML FormsEntering User Data from a Web Page

Page 23: HTML – Tables and Forms

HTML Forms Forms are the primary method for gathering data from site visitors

Create a form block with

Example:

23

<form></form>

<form name="myForm" method="post" action="path/to/some-script.php"> ...</form> The "action" attribute

tells where the form data should be sent

The “method" attribute tells how the form data should be sent – via GET

or POST request

Page 24: HTML – Tables and Forms

Form Fields Single-line text input fields:

Multi-line textarea fields:

Hidden fields contain data not shown to the user:

Often used by JavaScript code24

<input type="text" name="FirstName" value="This is a text field" />

<textarea name="Comments">This is a multi-line text field</textarea>

<input type="hidden" name="Account" value="This is a hidden text field" />

Page 25: HTML – Tables and Forms

Fieldsets Fieldsets are used to enclose a group

of related form fields:

The <legend> is the fieldset's title.25

<form method="post" action="form.aspx"> <fieldset> <legend>Client Details</legend> <input type="text" id="Name" /> <input type="text" id="Phone" /> </fieldset> <fieldset> <legend>Order Details</legend> <input type="text" id="Quantity" /> <textarea cols="40" rows="10" id="Remarks"></textarea> </fieldset></form>

Page 26: HTML – Tables and Forms

Form Input Controls Checkboxes:

Radio buttons:

Radio buttons can be grouped, allowing only one to be selected from a group:

26

<input type="checkbox" name="fruit" value="apple" />

<input type="radio" name="title" value="Mr." />

<input type="radio" name="city" value="Lom" /><input type="radio" name="city" value="Ruse" />

Page 27: HTML – Tables and Forms

Other Form Controls Dropdown menus:

Submit button:

27

<select name="gender"> <option value="Value 1" selected="selected">Male</option> <option value="Value 2">Female</option> <option value="Value 3">Other</option></select>

<input type="submit" name="submitBtn" value="Apply Now" />

Page 28: HTML – Tables and Forms

Other Form Controls (2) Reset button – brings the form to its

initial state

Image button – acts like submit but image is displayed and click coordinates are sent

Ordinary button – used for Javascript, no default action

28

<input type="reset" name="resetBtn" value="Reset the form" />

<input type="image" src="submit.gif" name="submitBtn" alt="Submit" />

<input type="button" value="click me" />

Page 29: HTML – Tables and Forms

Other Form Controls (3) Password input – a text field which

masks the entered text with * signs

Multiple select field – displays the list of items in multiple lines, instead of one

29

<input type="password" name="pass" />

<select name="products" multiple="multiple"> <option value="Value 1" selected="selected">keyboard</option> <option value="Value 2">mouse</option> <option value="Value 3">speakers</option></select>

Page 30: HTML – Tables and Forms

Other Form Controls (4) File input – a field used for uploading

files

When used, it requires the form element to have a specific attribute:

30

<input type="file" name="photo" />

<form enctype="multipart/form-data">... <input type="file" name="photo" />...</form>

Page 31: HTML – Tables and Forms

Labels Form labels are used to associate an

explanatory text to a form field using the field's ID.

Clicking on a label focuses its associated field (checkboxes are toggled, radio buttons are checked)

Labels are both a usability and accessibility feature and are required in order to pass accessibility validation.

31

<label for="fn">First Name</label><input type="text" id="fn" />

Page 32: HTML – Tables and Forms

HTML Forms – Example

32

<form method="post" action="apply-now.php"> <input name="subject" type="hidden" value="Class" /> <fieldset><legend>Academic information</legend> <label for="degree">Degree</label> <select name="degree" id="degree"> <option value="BA">Bachelor of Art</option> <option value="BS">Bachelor of Science</option> <option value="MBA" selected="selected">Master of Business Administration</option> </select> <br /> <label for="studentid">Student ID</label> <input type="password" name="studentid" /> </fieldset> <fieldset><legend>Personal Details</legend> <label for="fname">First Name</label> <input type="text" name="fname" id="fname" /> <br /> <label for="lname">Last Name</label> <input type="text" name="lname" id="lname" />

form.html

Page 33: HTML – Tables and Forms

HTML Forms – Example (2)

33

<br /> Gender: <input name="gender" type="radio" id="gm" value="m" /> <label for="gm">Male</label> <input name="gender" type="radio" id="gf" value="f" /> <label for="gf">Female</label> <br /> <label for="email">Email</label> <input type="text" name="email" id="email" /> </fieldset> <p> <textarea name="terms" cols="30" rows="4" readonly="readonly">TERMS AND CONDITIONS...</textarea> </p> <p> <input type="submit" name="submit" value="Send Form" /> <input type="reset" value="Clear Form" /> </p></form>

form.html (continued)

Page 34: HTML – Tables and Forms

form.html (continued)

HTML Forms – Example (3)

34

Page 35: HTML – Tables and Forms

TabIndex The tabindex HTML attribute controls the order in which form fields and hyperlinks are focused when repeatedly pressing the TAB key tabindex="0" (zero) - "natural"

order If X > Y, then elements with

tabindex="X" are iterated before elements with tabindex="Y"

Elements with negative tabindex are skipped, however, this is not defined in the standard

35

<input type="text" tabindex="10" />

Page 36: HTML – Tables and Forms

HTML Frames<frameset>, <frame> and <iframe>

Page 37: HTML – Tables and Forms

HTML Frames Frames provide a way to show multiple HTML documents in a single Web page

The page can be split into separate views (frames) horizontally and vertically

Frames were popular in the early ages of HTML development, but now their usage is rejected

Frames are not supported by all user agents (browsers, search engines, etc.) A <noframes> element is used to

provide content for non-compatible agents.

37

Page 38: HTML – Tables and Forms

HTML Frames – Demo

38

<html>

<head><title>Frames Example</title></head>

<frameset cols="180px,*,150px"> <frame src="left.html" /> <frame src="middle.html" /> <frame src="right.html" /> </frameset>

</html>

frames.html

Note the target attribute applied to the <a> elements in the left frame.

Page 39: HTML – Tables and Forms

Inline Frames: <iframe> Inline frames provide a way to show one website inside another website:

39

<iframe name="iframeGoogle" width="600" height="400" src="http://www.google.com" frameborder="yes" scrolling="yes"></iframe>

iframe-demo.html

Page 40: HTML – Tables and Forms

форум програмиране, форум уеб дизайнкурсове и уроци по програмиране, уеб дизайн – безплатно

програмиране за деца – безплатни курсове и уроцибезплатен SEO курс - оптимизация за търсачки

уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop

уроци по програмиране и уеб дизайн за ученициASP.NET MVC курс – HTML, SQL, C#, .NET, ASP.NET MVC

безплатен курс "Разработка на софтуер в cloud среда"

BG Coder - онлайн състезателна система - online judge

курсове и уроци по програмиране, книги – безплатно от Наков

безплатен курс "Качествен програмен код"

алго академия – състезателно програмиране, състезанияASP.NET курс - уеб програмиране, бази данни, C#, .NET, ASP.NET

курсове и уроци по програмиране – Телерик академия

курс мобилни приложения с iPhone, Android, WP7, PhoneGapfree C# book, безплатна книга C#, книга Java, книга C# Дончо Минков - сайт за програмиране

Николай Костов - блог за програмиранеC# курс, програмиране, безплатно

?? ? ?

??? ?

?

? ?

??

?

?

? ?

Questions?

?

HTML – Tables and Forms

http://academy.telerik.com

Page 41: HTML – Tables and Forms

Homework

41

6. Create Web Pages like the following using tables:

7. Create a Web Page like the following using forms:

Page 42: HTML – Tables and Forms

Homework (2)8. Create a Web

form that looks like this sample:

42

See the image Sample-form.png

Page 43: HTML – Tables and Forms

Free Trainings @ Telerik Academy

Web Applications with ASP.NET MVC Course mvccourse.telerik.com

Telerik Software Academy academy.telerik.com

Telerik Academy @ Facebook facebook.com/TelerikAcademy

Telerik Software Academy Forums forums.academy.telerik.com