Web Design Stuff
HTML Tutorials    CSS Tutorials    Web Hosting   Resources
Create a Web Page 101
Making Web Pages Intro What is a Web Page? Why Make a Web Page? The History of HTML Learn HTML or XHTML?
Basic HTML
Basic HTML Tutorials Basic HTML Necessities How to Make a Web Page How to Edit a Web Page The Basics of HTML Tags Basic HTML Page Structure HTML Attributes
HTML Font Codes
HTML Font Codes Intro HTML Font Color Codes HTML Font Size Codes HTML Font Style Codes HTML Bold/Italic Codes Combining Font Codes
Formatting Text
Formatting Text Intro Making Paragraphs Miscellaneous Formatting Headings & Subheadings Creating Hyperlinks
Using Graphics
Using Graphics on the Web Add Graphics to Your Pages Graphics and Accessibility How to Align Graphics Page Color & Background Graphics as Hyperlinks Horizontal Rules
Creating Tables
HTML Tables Tutorials HTML Table Fundamentals Background & Border Color Table Frames & Rules Table Width and Alignment Cells 1 -Space & Alignment Cells 2 -Row Column Span Cells 3 -Width & Height
Making Lists
HTML Lists Tutorials Bulleted Lists Numbered Lists Definition Lists
HTML Frames
HTML Frames Tutorials Using Frames for Layout Advanced Frame Layouts Putting Hyperlinks in Frames Frame Border Width Color, Margin and Control Problems with Frames SmartFrames: A Solution SSI: An Alternative to Frames
Web Page Forms
Making Feedback Forms A Simple Feedback Form Installing NMS FormMail Debugging Your Setup My Web Host is Out to Lunch User Input Components Text Fields Checkboxes & Radio Buttons Dropdown Menus Push Buttons Layout and Presentation
Basic CSS
Basic CSS Tutorials What is CSS? Why You Should Use CSS How to Use CSS Inline Styles Embedded Style Sheets External Style Sheets Class Selectors ID Selectors Combining Selectors
CSS Properties
CSS Properties Intro Font Styles Width, Height & Spacing Borders Backgrounds Position Float & Alignment Hyperlinks
All About Web Hosting
Hosting Your Own Website What is a Web Host? Your Website's Home Page Building a Website Offline About Free Web Hosting Best Free Web Hosting Commercial Web Hosting How to Get a Domain Name Ecommerce Web Hosting Web Hosting Terminology
Free Web Design Tools
Best Free Website Tools Best Free Text Editors Best Free Graphics Editors Free Website Analysis Tools
Setting Up HTML Kit
HTML Kit Introduction How to install HTML Kit Screenshot Breakdown Basic Configuration Overall Appearance Shortcuts and Startup Editing Window Customizing Toolbars Using the Favorites Tab Making a New Actions Bar Odds and Ends
Free Templates
Free Website Templates Two Column Fixed Width Three Column Liquid Layout Miscellaneous Templates Dynamic Menu Effects Two Column Experimental Terms of Use About These Templates
Website Templates Help
Getting Started Template Zip File Download How to Edit Your Template What to Edit in the HTML How to Add Your Logo Making a Website
Web Design Tips
Web Design Basics Tables vs. Tableless Using Tables for Layout Example Table Layouts World's Crappiest Web Page
Twitter Backgrounds
Twitter Backgrounds Intro Cool Twitter Backgrounds Cool Twitter Backgrounds 2 Plain Twitter Backgrounds Dark Twitter Backgrounds Best Twitter Backgrounds Cute Twitter Backgrounds Music Twitter Backgrounds Music Twitter Backgrounds 2 Twitter Backgrounds 101 TERMS OF USE
All About Web Browsers
What is a Web Browser? Mozilla Firefox Internet Explorer Opera How to Set Up Firefox Top 5 Firefox Extensions
 
Contact
Post Some Feedback Send Me An Email Iron Spider Blog About Iron Spider... Site Conventions
 
 
 

 

Table Cells - Row and Column Span

 
<td
colspan="columns"
rowspan="rows">
...</td>
 
 
Defines how many columns cell will span
Defines how many rows cell will span
 
When constructing an HTML table, the number of rows are established by the number of <tr>...</tr> tag pairs while the number of columns are established by the number of <td>...</td> tag pairs in each row. Typically, the table will be layed out like a grid with each cell's width equal to the width of one column and each cell's height equal to the height of one row. You may, however, have any cell spread over or 'span' the width of multiple rows or columns using special attributes in the <td> tag.

These attributes are described in more detail below:
  • colspan="number of columns" ~ By default, the number of columns in a table is defined by the number of table data cells appearing in the table row that contains the most. You would, however, typically place the same number of data cells in each and every table row. If a table row does not contain the requisite number of table cells then it will essentially be in 'error' and will be displayed with a missing cell.

    In Example 1A, the first row only contains one table cell whereas all the other rows contain two. Hence the table is defined as having two columns and the first row is displayed with its second cell missing. Let's blow apart the source code so that the table rows are clearly discernable:

    Example 1A - SOURCE CODE (first table row contains only one cell)

    <table border="3" bordercolor="#c86260" bgcolor="#ffffcc" width="50%" cellspacing="5" cellpadding="3">

    <tr><td>MY DAILY MENU</td></tr>

    <tr><td valign="top"><b>Breakfast</b></td><td>Orange juice<br>Toast<br>Black coffee</td></tr>

    <tr><td valign="top"><b>Lunch</b></td><td>Tuna sandwich<br>Apple</td></tr>

    <tr><td valign="top"><b>Dinner</b></td><td>Hamburger steak<br>Mashed potatoes<br>Green beans<br>Jello</td></tr>

    </table>


    Example 1A - RESULT (first table row contains only one cell)
    MY DAILY MENU
    BreakfastOrange juice
    Toast
    Black coffee
    LunchTuna sandwich
    Apple
    DinnerHamburger steak
    Mashed potatoes
    Green beans
    Jello
    <~Missing table cell


    This situation can be remedied using the colspan attribute whose value defines how many columns a table cell will span. Hence, a <td> tag using a colspan="2" attribute-value pair will specify that that particular cell will stretch over the equivalent of two columns worth of space:

    Example 1B - SOURCE CODE (cell spans two columns)

    <table border="3" bordercolor="#c86260" bgcolor="#ffffcc" width="50%" cellspacing="5" cellpadding="3">

    <tr><td align="center" colspan="2">MY DAILY MENU</td></tr>

    <tr><td valign="top"><b>Breakfast</b></td><td>Orange juice<br>Toast<br>Black coffee</td></tr>

    <tr><td valign="top"><b>Lunch</b></td><td>Tuna sandwich<br>Apple</td></tr>

    <tr><td valign="top"><b>Dinner</b></td><td>Hamburger steak<br>Mashed potatoes<br>Green beans<br>Jello</td></tr>

    </table>


    Example 1B - RESULT (cell spans two columns)
    MY DAILY MENU
    BreakfastOrange juice
    Toast
    Black coffee
    LunchTuna sandwich
    Apple
    DinnerHamburger steak
    Mashed potatoes
    Green beans
    Jello

    Note that, as well as using colspan="2" in the 'MY DAILY MENU' table cell to make it span two columns, we also used align="center" to center the content.


  • rowspan="number of rows" ~ The rowspan attribute works just like the colspan attribute except that you may find the situation a little more difficult to visualize when working with the source code. But once again the principle is the same. By using the rowspan attribute, you can force a table cell to span the number of rows specified by the respective value.

    In the following example, the 'MONDAY' table cell spreads over three table rows:

    Example 2 - SOURCE CODE (cell spans three rows)

    <table border="3" bordercolor="#c86260" bgcolor="#ffffcc" width="50%" cellspacing="5" cellpadding="3">

    <tr><td align="center" colspan="3">MY DAILY MENU</td></tr>

    <!-- FIRST CELL IN THIS ROW SPANS THE NEXT 3 ROWS --> <tr><td rowspan="3">M<br>o<br>n<br>d<br>a<br>y</td><td valign="top"><b>Breakfast</b></td><td>Orange juice<br>Toast<br>Black coffee</td></tr>

    <tr><td valign="top"><b>Lunch</b></td><td>Tuna sandwich<br>Apple</td></tr>

    <tr><td valign="top"><b>Dinner</b></td><td>Hamburger steak<br>Mashed potatoes<br>Green beans<br>Jello</td></tr>

    </table>


    Example 2 - RESULT (cell spans three rows)
    MY DAILY MENU
    M
    o
    n
    d
    a
    y
    BreakfastOrange juice
    Toast
    Black coffee
    LunchTuna sandwich
    Apple
    DinnerHamburger steak
    Mashed potatoes
    Green beans
    Jello
The width and height of all the cells in your HTML table is automatically set by the web browser displaying the page according to how much content is in each cell. You can, however, explicitly set how wide and how high to display your table data cells...





Best Free Stuff
for webmasters

Free Text Editors
Free Graphics Editors
Website Analysis Tools
Free Website Templates

See also:

Best Free Web Hosting

 

If you need a .COM web address, you can get one quick and easy at...

www.GoDaddy.com
<~BACK TOP NEXT ~>
 
HTML Tutorials |  CSS Tutorials |  Web Hosting |  Domain Names |  Web Design Resources
Iron Spider © Copyright 2004-2011 Robert Darrell