|
|
|
|
|
|
Author Rank:
|
|
Total page views :
1262
|
|
Total downloads :
|
|
|
|
|
|
|
Similar ArticlesMost ReadTop RatedLatest
|
|
|
|
|
|
|
|
|
|
In this article you will learn that tables have many uses in HTML. The most obvious is a table of data, but tables can also be used to place graphics on a page at just the right spot or to format text and form input boxes, or simulate columns.
Table format is widely used in webpage designing and provide you with greater control over displaying of information on web page. They allow you to create boundaries that make positioning easier.
Tables
<table> </table>
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). The letters td stands for "table data," which is the content of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc.
Row Tag
Each table has at least one row and within that row are columns or what is also referred to as cells.
<tr>...</tr>
You can have N number of rows in your table.
Table Heading Tag
A table can have heading. Headings in a table are defined with the help of <th> tag.
<th>...</th>
Column/Cell tag
You have columns in your table where you can have your text, image etc.
<td>...</td>
HTML coding to create a simple table:
<html> <head> <title>Tables in HTML</title> </head> <body> <h1> How to create table in HTML</h1> <table> <tr> <th> Names </th> <th> Designation </th> <th> Salary </th> </tr> <tr> <td> Rocky </td> <td> Assistant </td> <td> $2300 </td> </tr> </tr> <tr> <td> Peter </td> <td> Manager </td> <td> $5700 </td> </tr> </tr> <tr> <td> Samantha </td> <td> Teacher </td> <td> $7600 </td> </tr> </tr> <tr> <td> Catherine </td> <td> President </td> <td> $4500 </td> </tr> </tr> <tr> <td> Michael </td> <td> Author </td> <td> $3700 </td> </tr> </table> </body> </html>
Adding Table Borders
You can create border for the table. You have include border attribute in the opening table tag. You can also add color attribute to the border. So in the above table the code would be adjusted accordingly:
<html> <head> <title>Tables in HTML</title> </head> <body> <h1> How to create table in HTML</h1> <table border="2" bordercolor="blue"> <tr> <th> Names </th> <th> Designation </th> <th> Salary </th> </tr> <tr> <td> Rocky </td> <td> Assistant </td> <td> $2300 </td> </tr> </tr> <tr> <td> Peter </td> <td> Manager </td> <td> $5700 </td> </tr> </tr> <tr> <td> Samantha </td> <td> Teacher </td> <td> $7600 </td> </tr> </tr> <tr> <td> Catherine </td> <td> President </td> <td> $4500 </td> </tr> </tr> <tr> <td> Michael </td> <td> Author </td> <td> $3700 </td> </tr> </table> </body> </html>
Adjusting Table Cell Spacing and Cell Padding
You can increase the space within the table cells and the space between the cells by using the cell padding and cell spacing attributes.
The cell spacing attribute adjusts the space between the cells and cell padding adjusts the space within (around) the cell.
<table border="2" bordercolor="red" cellspacing="5" cellpadding="5">
Implement this line code into your previous code and see the change: <html> <head> <title>Tables in HTML</title> </head> <body> <h1> How to create table in HTML</h1> <table border="2" bordercolor="red" cellspacing="5" cellpadding="5"> <tr> <th> Names </th> <th> Designation </th> <th> Salary </th> </tr> <tr> <td> Rocky </td> <td> Assistant </td> <td> $2300 </td> </tr> </tr> <tr> <td> Peter </td> <td> Manager </td> <td> $5700 </td> </tr> </tr> <tr> <td> Samantha </td> <td> Teacher </td> <td> $7600 </td> </tr> </tr> <tr> <td> Catherine </td> <td> President </td> <td> $4500 </td> </tr> </tr> <tr> <td> Michael </td> <td> Author </td> <td> $3700 </td> </tr> </table> </body> </html>
Specifying a Table Width
You can specify the width of a table by using either a percentage or a pixel width.
<table width="100%" border="2" bordercolor="red" cellspacing="5" cellpadding="5">
When you set the width of the table as 100% it will take the entire screen space and the columns will be adjusted evenly. Use the previous code and make the changes and see the output.
Specifying a Table Height
You can also set the table height by adding the height tag to the table code.
<table width="100%" height="500" border="2" bordercolor="red" cellspacing="5" cellpadding="5">
You can specify the table width and height in percentage of pixel. Mostly people prefer percentage because it will adjust accordingly irrespective of the monitor size.
Setting Column Widths
It is not always necessary that you would want all the columns of same size. You can change the column width of individual column.
<td width="30%">Rocky</td> <td width="50%">Assistant</td> <td width="20%">$2300</td> Add the above code in one row and see the output changes. You can specify the width either in percentage or pixel.
Column/cell tag and its attributes
You can also use other attributes in the column/cell tag, such as:
align: sets your text or image to left, center or right
valign: sets your content vertically to top, center or bottom
rowspan: expands over multiple rows
colspan: expands across multiple columns/cells
Align attribute
Leaving your text or image to the left of your column is usually pretty boring, so the align attribute lets you center things, using "center" or place them to the right, using "right".
<th align="center">Names</th> <th align="right">Designation</th> <th align="left">Salary</th> In the above code I have include all three horizontal alignment left, right and center. By default the alignment is left.
Valign attribute
When placing copy in a column, the browser will automatically place it in the center of the column. You can change this default by using the valign attributes of "top", "center" or "bottom".
<td valign="top">Rocky</td> <td valign="bottom">Assistant</td> <td valign="center">$2300</td> In the above code I have include all three vertical alignment top, bottom and center. By default the vertical alignment is center.
Row Span
rowspan is used to expands over multiple rows
<td rowspan="2" width="30%" valign="top">Rocky</td> <td width="50%" valign="bottom">Assitant</td> <td width="20%" align="center">$2300</td> Column Span colspan expands across multiple columns/cells
<td colspan="2">Michael</td> <td>Author</td> <td>$3700</td>
Hope this article would have helped you in understanding table and now you can use it to full effectiveness.
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
|
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today. With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications. Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
|
60 FREE UI Controls from DevExpress
Register for your FREE copy on over 60 free presentation controls from
DevExpress - Absolutely Free-of-Charge without any royalties or distribution
costs. Visit Devexpress.com/60 today. Free controls include advanced lists box, dropdown calendar, rich text edit, spin
edit, tab control and so much more!
DevExpress engineers feature rich presentation controls and reporting tools for WinForms, ASP.NET, WPF, and Silverlight. Our technologies help you build your best, see complex software with greater clarity and deliver compelling business solutions for Windows and the web in the shortest possible time.
|
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or
application via a range of API's. Learn More about our API connections.
|
Microsoft Visual Studio 2010
Visualize your workspace with new multiple monitor support, powerful Web development, new SharePoint support with tons of templates and Web parts, and more accurate targeting of any version of the .NET Framework. Get set to unleash your creativity.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
|
|
|
|
|
|
|
|
|
|
|
|
|