Help:Wiki University Wikitext--Tables - Column Spans





<< Previous Chapter Next Chapter >>

Spanning columns in tables
This ability to span columns is especially useful when separating sections of one table into different topics.
 * When we create tables, sometimes we want a cell to cover more than one column like in the following example:
 * NOTICE the first row consists of two cells, each spanning two cells of the following row.

How to span columns

 * If we want to span two columns, for example, we use a class called "colspan."

colspan="2"


 * This coding is inserted right after either the | or ! tags.


 * When using the pipe "|", you will need to add in the "text-align:center" attribute in order for the name to be centered:

 | colspan="2" style="text-align:center " | Foods that have a .......


 * If you use the "!" instead of the pipe "|", then the name defaults to the center and is bolded:

 ! colspan="2" style="" | Foods that have a .......


 * Here is the coding for the first three rows of the above table using a pipe:


 * NOTICE again the location of the class "colspan."
 * NOTICE that the new row only has two cells, but each cell has a "colspan" in it. The two colspans cover the four cells in the next row.

Columns have to add up

 * Make sure that the columns you span add up to the total number of cells in the next row.
 * If you span a total of four columns or cells, you must have two colspan="2" in the preceding row, otherwise you will get who knows what!

Restrictions

 * You cannot create sortable tables with colspans.

Try these out


 Exercises
 * Use this coding for a table

Check your answers
 * Merge all the cells in the second row.
 * Merge the first three cells in the fourth row.

 Quick Quiz
 * Colspans must equal the number of cells in the next row.
 * A. True
 * B. False


 * If you have a row with four cells you can have in the preceding row one cell with a colspan="3" plus the remaining cell.
 * A. True
 * B. False


 * If you have a row of seven cells you can have in the preceding row one cell with a colspan="2", the next cell with a colspan="3" and the remaining cell with a colspan="2".
 * A. True
 * B. False

Check your answers

<< Previous Chapter Next Chapter >>