Saturday, April 14, 2012

HTML Beginner tutorial 12 : HTML Tables

HTML Tables
Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain text, links, images, lists, forms, other tables, etc.
For Example

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 3</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
<td>row 2, cell 3</td>
</tr>
</table>

How the HTML code above looks in a browser:

row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3

HTML Tables and the Border Attribute
If you do not specify a border attribute, the table will be displayed without borders. Sometimes this can be useful, but most of the time, we want the borders to show. To display a table with borders, specify the border attribute:

<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>

HTML Table Headers
Header information in a table are defined with the <th> tag. All major browsers display the text in the <th> element as bold and centered.

<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 3</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
<td>row 2, cell 3</td>
</tr>
</table>

How the HTML code above looks in your browser:

Header 1 Header 2 Header 3
row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3

HTML Table Tags

Tag Description
<table> Defines a table
<th> Defines a table header
<tr> Defines a table row
<td> Defines a table cell
<caption> Defines a table caption
<colgroup> Defines a group of columns in a table, for formatting
<col /> Defines attribute values for one or more columns in a table
<thead> Groups the header content in a table
<tbody> Groups the body content in a table
<tfoot> Groups the footer content in a table

HTML Beginner tutorial 13 : HTML Lists  >>
<<  HTML Beginner tutorial 11 : HTML Images

Thursday, April 12, 2012

HTML Beginner tutorial 11 HTML Images

The <img> Tag and the Src Attribute
In HTML, images are defined with the <img> tag. The <img> tag is empty, which means that it contains attributes only, and has no closing tag.
To display an image on a page, you need to use the src attribute. Src stands for "source". The value of the src attribute is the URL of the image you want to display.
Syntax for defining an image:

<img src="url" alt="text here"/>

The URL points to the location where the image is stored. An image named "boat.gif", located in the "images" directory on "www.yoursite.com" has the URL: http://www.yoursite.com/images/boat.gif.

The browser displays the image where the <img> tag occurs in the document. If you put an image tag between two paragraphs, the browser shows the first paragraph, then the image, and then the second paragraph.

The Alt Attribute
The required alt attribute specifies an alternate text for an image, if the image cannot be displayed. The value of the alt attribute is an author-defined text.

<img src="boat.gif" alt="Big Boat" />

The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).

Set Height and Width of an Image
The height and width attributes are used to specify the height and width of an image. The attribute values are specified in pixels by default.

<img src="img.jpg" alt="rock" width="300" height="220" />

It is a good practice to specify both the height and width attributes for an image. If these attributes are set, the space required for the image is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the image. The effect will be that the page layout will change during loading (while the images load).

Basic Notes
If an HTML file contains ten images - eleven files are required to display the page right. Loading images takes time, so my best advice is, Use images carefully.

When a web page is loaded, it is the browser, at that moment, that actually gets the image from a web server and inserts it into the page. Therefore, make sure that the images actually stay in the same spot in relation to the web page, otherwise your visitors will get a broken link icon. The broken link icon is shown if the browser cannot find the image.

HTML Beginner tutorial 12 : HTML Tables  >>
<<  HTML Beginner tutorial 10 : HTML Links

Wednesday, April 11, 2012

HTML Beginner tutorial 10 HTML Links

HTML Hyperlinks
A hyperlink is a word, group of words, or image that you can click on to jump to a new document or a new section within the current document.
When you move the cursor over a link in a Web page, the arrow will turn into a little hand. Links are specified in HTML using the <a> tag.
The <a> tag can be used in two ways:
  • To create a link to another document, by using the href attribute
  • To create a bookmark inside a document, by using the name attribute

HTML Link Syntax
The HTML code for a link is simple. It looks like this:

<a href="url">Some text here</a>

The href attribute specifies the destination of a link.
For example

<a href="http://webdesignpluscode.blogspot.com/">Visit Tutorials</a>

which will display like this: Visit Tutorials
Clicking on this hyperlink will send the user to Web design plus code's homepage.
The "Link text" doesn't have to be text. It can be an image or any other HTML element.

HTML Links - The target Attribute
The target attribute specifies where to open the linked document. The example below will open the linked document in a new browser window or a new tab.

<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>

HTML Links - The name Attribute
The name attribute specifies the name of an anchor. The name attribute is used to create a bookmark inside an HTML document.
The upcoming HTML5 standard suggests using the id attribute instead of the name attribute for specifying the name of an anchor. Using the id attribute actually works also for HTML4 in all modern browsers.
Bookmarks are not displayed in any special way. They are invisible to the reader.
For example
A named anchor inside an HTML document:

<a name="tips">Useful Tips Section</a>

Create a link to the "Useful Tips Section" inside the same document:

<a href="#tips">Visit the Useful Tips Section</a>

Or, create a link to the "Useful Tips Section" from another page:

<a href="http://www.yoursite.com/html_links.htm#tips">Visit the Useful Tips Section</a>

Basic Notes
Always add a trailing slash to subfolder references. If you link like this: href="http://www.site.com/html", you will generate two requests to the server, the server will first add a slash to the address, and then create a new request like this: href="http://www.site.com/html/".
Named anchors are often used to create "table of contents" at the beginning of a large document. Each chapter within the document is given a named anchor, and links to each of these anchors are put at the top of the document.

HTML Beginner tutorial 11 : HTML Images  >>
<<  HTML Beginner tutorial 9 : HTML Styles

Tuesday, April 10, 2012

HTML Beginner tutorial 9 HTML Styles

Styling HTML with CSS
CSS is used to style HTML elements.
CSS was introduced together with HTML 4, to provide a better way to style HTML elements.
CSS can be added to HTML in the following ways:
  • in Cascading Style Sheet files (CSS files)
  • in the <style> element in the HTML head section
  • in the style attribute in single HTML elements

Using the HTML Style Attribute

It is time consuming and not very practical to style HTML elements using the style attribute.
The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files.
However, in this HTML tutorial we will introduce you to CSS using the style attribute. This is done to simplify the examples.

HTML Style  - Background Color

The background-color property defines the background color for an element:
For example

html style background color
html style background color.


The background-color property makes the "old" bgcolor attribute obsolete.


HTML Style - Font, Color and Size

The font-family, color, and font-size properties defines the font, color, and size of the text in an element:
For example

html style font color size
html style font color size.


The font-family, color, and font-size properties make the old <font> tag obsolete.


HTML Style - Text Alignment

The text-align property specifies the horizontal alignment of text in an element:
For example

html style text alignment
html style text alignment.


The text-align property makes the old <center> tag obsolete.


HTML Beginner tutorial 10 : HTML Links  >>

<<  HTML Beginner tutorial 8 : HTML Fonts

HTML Beginner tutorial 8 HTML Fonts

The HTML <font> Tag Should NOT be Used
The <font> tag is deprecated in HTML 4, and removed from HTML5.
The World Wide Web Consortium (W3C) has removed the <font> tag from its recommendations.
In HTML 4, style sheets (CSS) should be used to define the layout and display properties for many HTML elements.
The example below shows how the HTML could look by using the <font> tag:

html fonts
html fonts.


The Right Way to Do It, is using Styles. Which 'll be discuss in next tutorials.

HTML Beginner tutorial 9 : HTML Styles  >>
<<  HTML Beginner tutorial 7 : HTML Text Formatting