A Web Tutorial Series: Looking at More HTML Structures: Tables, Blocks, Forms & More!
Recap of the Previous Tutorial in the Series
In our previous tutorial, A Web Tutorial Series: The HTML Anchor Tag, More on Problem Solving, & Using Browser Development Tools, we looked primarily at the anchor tag to link our own content and with "outside world" content. As an aside we touched on development tools. My philosophy regarding development and debugging tools is that they should be incorporated throughout the learning process. As a software developer with four decades of experience, I know that you really need to have a basic understanding of where help is available before you run into problems. Studying help doesn't help, knowing there are avenues for solving problems is what is important. With that said, from time to time such "sidebars" will be included in these tutorials.
Scope of This Tutorial and What Will Follow
In this tutorial we return to the structural elements of a page. We will look at tables, forms and blocks. Tables are a great way to visually encapsulate condensed data and they are often what attracts reads to a page. Forms are a mechanism for allowing a web site visitor to interact with the web site creator. With blocks we will start with spans and divs. When first looking at web design, I had no problem understanding spans. What I had problems with were divs. I understood the concept, but I became lost in the implementation. Unfortunately, divs are a legacy and at times seem to be a necessary evil, however with HTML 5 we can get away frim the div-it is of the past with new tags which make a whole lot more sense. So following this introduction to blocks in this tutorial, the next tutorials will concentrate on the new tag: the header, footer, section, aside, nav, etc. which will then precede laying out the page.
Basic Table Structure
A basic table involves the use of four main tags:
- the <table> and </table> tags which mark the beginning and end of the table
- the <tr> and </tr> which delineate a row in the table
- the <td> and </td> which essentially divides the row into columns, the formal name is "data cells"
- the table can have headings, which can be divided so that specific columns can be identified as to their content. The heading tags are <th> and </th>.
Tables can use other tags. They may include text, images, lists, and other tables. Any valid CSS styling can be applied to the table without restriction.
For an example of how complex a table in HTML may become see the illustration at the footer of this page.
A HTML Table Created from Images of Saturn
A Simple Table
An example of a very simple table follows in the snapshot.. It is not pretty as yet but it is functional.
Applying a Little CSS Magic to Our Table
A Simple Table: The Alphabet
It Doesn't Take Much to Improve This Table
Aout 10 minutes maximum time and this table can look presentable. Other things which can be experimented with could be table size, differnt fornts, different colors and borders.
As we make use of tables in future tutorials we will point out different techniques for improving upon the basic.
The following snapshot show what 10 minutes of effor can accomplish.
Basic HTML Form Structure
HTML5 adds a whole new dimension to forms with a host of new input types, form elements and attributes. The additions will cover several tutorials in the future. Rather than be overwhelmed now we will just look at the basic construction of a form.
A form serves a significant purpose in web design and construction. A form allows a user (a client) to communicate with some server application.
The outline of a form consists of the <form></form? tags.Within the form tags one can have text fields, radio-buttons and checkboxes, submit buttons, password fields and more. The following illustrates the form elements.
The Input Element: The Most Important Form Element
The most imprtant element on a form is the input element. The input element is the way the user of the page select what actions the y wich to perform.The input element tag is a self-closing tage. <input>
The following snapshot illustrates a simple login form. In our illustration we will use two types of input. A text input for the user name and a password type input for the users password. A password type input differs from a text input in that it masks out the data being entered.
The Input Text and Input Password Elements
The Submit Button - Makes it Happen
The submit button is what makes if not "the world go 'round" at least directs the data a a server application. This is beyond the scope of this tutorial. The coding of the submit button itself is rather simple. It involves the <input> tag with a type specification of submit and a value field which indicates the what information is placed on the button.
For processing of the data changes are made to the form element itself. The submit button merely triggers the form action.
The Form Example Updated with the Submit Button
Two Other Basic Input Mechanisms
The final two basic methods of input we will consider here are the checkbox and radio button types. They differ in appearance. The are also distinguished in that radio buttons permit the selection of only one option while checkboxes permit no selection or multiple selections. The snapshots which follow illustrate the use of both.
The Checkbox and Radio Button Input Types
Introduction to Blocks
This is just the beginning and it becomes critical in creating web pages: the understing of the difference between HTML block elements and HTML inline elements.
Most HTML elements are defined as block elements. They are stacked on top of one another.: headers <h1> through <h6> , <tables>, and <p> for example.
Inline elements are arraged vertically. They don't "stack".
The two elements we discuss now are the<div> element and the <span> element. The <div> eleent is a block element. Yhe <span> element is a inline element.
Now, come the hard part. Neither the <div> nor the <span> have any special meaning.. It is what you make out of them. They are merely containers. In versions before HTML 5 <divs> became notorious in creating confusion with their use. With HTML 5 with more element types to choose from it has become easier to style pages and get away from divs.
Here's a final way in which to begin to comprehend <span> and <div>. If I have one word in a paragraph which for some reason I want displayed in the color red, I would use a <span> with the color style specified. This is an inline use. If I have a block of text to which I want to specify a specific styling to, I would use a <div>, As noted, with HTML5 and its additional element types, I might be able syle elements rather than style a <div>.We will revisit this discussion againg as there are many legacy pages which are "over<div>'ed"
A HTML Rendering of the Chemical Periodic Table
Wrap Up and What's Next
In this tutorial we looked at significant HTML block elements: tables and forms. We touched on the notions of block and inline structures and briefly discussed <div>'s and <span>'s which were the only ways of making styling more specific with the limited number of HTML element types in earlier versions of the product.
In our next tutorial we will begin looking at some of the new HTML 5 element types a s we work toward a goal of structuring our content in an effective manner so that when we apply styling we will have elegant web pages and web sites.