Welcome to Wars Wiki!
Welcome, new users! For help on where to start, look at our getting started page and our manual of style. Need more help? Ask a staff member!
Greetings to participants of Indie Wiki Jam 2024. Check out our Indie Wiki Jam portal here.

User:Moydow/Sandbox

From Wars Wiki
Jump to navigationJump to search

Tables are a very useful tool for presenting data neatly. There are many different ways of using wikicode, HTML, and CSS, to achieve the desired appearance of the table, although in most situations, only the basics are required. Experiment in the Sandbox to get a feel for designing tables, and don't hesitate to ask for help where necessary.

Basic coding[edit | edit source]

Basic coding used in designing a table.
Code Purpose
{| Begins a table. Immediately after this, CSS coding (such as class="wikitable") to define the table's appearance should be written.
|+ Used between the table's start and first row to add a caption (which appears above the table, as above).
|- Defines the end of a row, and the beginning of a new one. It may be omitted at the end of the final row.
! Defines a heading. All text in this cell will be bolded, and centred, and the cell will be highlighted.
| Defines a basic cell.
|} Ends the table.
  • Important: Each code must be placed at the beginning of a new line. However, an entire row may be placed on one line, by duplicating the code used to begin the row. This is explained further below.

Simple tables[edit | edit source]

A series of basic tables, and the required coding.
Description Wikicode Result
The most basic table, a 3x2 table with three headers.
{| class="wikitable"
! Header 1
! Header 2
! Header 3
|-
| Cell 1
| Cell 2
| Cell 3
|}
Header 1 Header 2 Header 3
Cell 1 Cell 2 Cell 3
The same table, with an added caption.
{| class="wikitable"
|+ A test table
! Header 1
! Header 2
! Header 3
|-
| Cell 1
| Cell 2
| Cell 3
|}
A test table
Header 1 Header 2 Header 3
Cell 1 Cell 2 Cell 3
The same table, with the wikicode contained on one line per row.
{| class="wikitable"
! Header 1 !! Header 2 !! Header 3
|-
| Cell 1 || Cell 2 || Cell 3
|}
Header 1 Header 2 Header 3
Cell 1 Cell 2 Cell 3
An extended table, with randomly added header cells. Any cell can be designated as a "header" by using the ! mark. Note that this effect cannot be achieved with the wikicode contained on one line per row.
{| class="wikitable"
| Header 1
! Header 2
| Header 3
|-
| Cell 1
| Cell 2
! Cell 3
|-
! Cell A
! Cell B
| Cell C
|}
Header 1 Header 2 Header 3
Cell 1 Cell 2 Cell 3
Cell A Cell B Cell C

colspan and rowspan: Irregular-sized cells[edit | edit source]

One cell can be made to span several rows or columns, by using the colspan and rowspan attributes. This has various useful applications. However, the fact that these attributes eliminate certain cells from other parts of the table's coding can significantly increase the overall complexity of the table. Using the Sandbox and the "Show preview" button to learn how these attributes affect a table's appearance is extremely helpful. The attributes accept a numerical value representing the number of rows or columns a single cell should span. This value should be no less than two, and no greater than the total number of rows or columns in the table. The attributes are added to a cell before the cell's actual content, separated from it by a pipe symbol (|), as follows:

|colspan="2"|Cell content

.

An example of a table using colspan:

{| class="wikitable"
! Header 1
! Header 2
! Header 3
|-
|colspan="2"|Cell 1+Cell 2
| Cell 3
|}
Header 1 Header 2 Header 3
Cell 1+Cell 2 Cell 3

rowspan is more difficult to code:

{| class="wikitable"
!rowspan="2"|Header 1+Cell 1
! Header 2
! Header 3
|-
| Cell 2
| Cell 3
|}
Header 1+Cell 1 Header 2 Header 3
Cell 2 Cell 3