User:Timeshifter/Sandbox240

More cell operations.

Help:Table#More cell operations

Setting cell parameters

At the start of a cell, add your parameter followed by a single pipe. For example, style="width: 300px;"| sets that cell to a width of 300 pixels. To set more than one parameter, leave a space between each one.

Wikitext

style="color: white;"
style="background: red;"|cell1

| style="width: 300px; background: blue;"|cell2

| style="background: green;"|cell3

Produces

style="color:white"
style="background: red;"|cell1style="width: 300px; background: blue;"|cell2

| style="background: green;"|cell3

Vertical alignment in cells

By default, text is aligned to the vertical middle of the cell:

class=wikitable style="width: 400px;"
scope="row" style="width: 10%;" | Row header

| style="width: 70%;"|A longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Imagine someone scrolling down the page, seeing the tops of "empty" columns, and wondering why they're empty.

| style="width: 20%;"|Short text

To align the text to the top of the cell, apply the style="vertical-align: top;" CSS to the rows (unfortunately, it seems to be necessary to apply this individually to every single row). The valign=... attribute is deprecated and MediaWiki may stop using it.

Wikitext

class=wikitable style="width: 400px;"
style="vertical-align: top;"

! scope="row" style="width: 10%;" | Row header

| style="width: 70%;"|A longer piece ...

| style="width: 20%;"|Short text

Produces

class=wikitable style="width: 400px;"
style="vertical-align: top;"

! scope="row" style="width: 10%;" | Row header

| style="width: 70%;"|A longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Imagine someone scrolling down the page, seeing the tops of "empty" columns, and wondering why they're empty.

| style="width: 20%;"|Short text

Cell content indenting and padding

The contents of a cell can be indented or padded on any side. Also, the text can be aligned. In the second row the text is aligned to the right. See the following examples.

Wikitext

class=wikitable
Cell content that is not indented or padded
style="padding-left: 2em;" | style="padding-left: 2em;"
style="text-align:right; padding-right: 2em;" | style="text-align:right; padding-right: 2em;"
style="padding-top: 2em;" | style="padding-top: 2em;"
style="padding-bottom: 2em;" | style="padding-bottom: 2em;"
style="padding: 3em 5%;" | style="padding: 3em 5%;" {{space|4}} (Top and Bottom: 3em. Left and Right: 5%)
style="padding: 3em 4em 5%;" | style="padding: 3em 4em 5%;" {{space|4}} (Top: 3em. Left and Right: 4em. Bottom: 5%)
style="padding: 3%;" | style="padding: 3%;" {{space|4}} (Top, Right, Bottom, and Left: all 3%)
style="padding: 1em 20px 8% 9em;" | style="padding: 1em 20px 8% 9em;" {{space|4}} (Top: 1em. Right: 20px. Bottom: 8%. and Left: 9em.)

Produces

class=wikitable
Cell content that is not indented or padded
style="padding-left: 2em;" | style="padding-left: 2em;"
style="text-align:right; padding-right: 2em;" | style="text-align:right; padding-right: 2em;"
style="padding-top: 2em;" | style="padding-top: 2em;"
style="padding-bottom: 2em;" | style="padding-bottom: 2em;"
style="padding: 3em 5%;" | style="padding: 3em 5%;" {{space|4}} (Top and Bottom: 3em. Left and Right: 5%)
style="padding: 3em 4em 5%;" | style="padding: 3em 4em 5%;" {{space|4}} (Top: 3em. Left and Right: 4em. Bottom: 5%)
style="padding: 3%;" | style="padding: 3%;" {{space|4}} (Top, Right, Bottom, and Left: all 3%)
style="padding: 1em 20px 8% 9em;" | style="padding: 1em 20px 8% 9em;" {{space|4}} (Top: 1em. Right: 20px. Bottom: 8%. and Left: 9em.)

{{clear}}

{{anchor|Pattern for arguments involving four sides|Clock order}}

File:Westclox Big Ben.jpg

;Pattern for arguments:

The arguments to style="padding: " can be seen as being ordered by a 12-hour clock, starting at noon and going clockwise, in the following sense: "top" is associated with noon (i.e. 12 o'clock, the top of a clock), "right" is 3 o'clock, "bottom" is 6 o'clock, and "left" is 9 o'clock. The arguments are ordered clockwise starting at noon: top → right → bottom → left (see thisIn style="padding: 3em 4em 5%;", the value 4em is used for both the "left" padding and the "right" padding, so the order going clockwise is: top (3em) → right [and hence also left] (4em) → bottom (5%); there is no "→ left" in this case because the "left" padding has already been defined. In style="padding: 3em 5%;", the value 3em is used for both the "top" and "bottom" padding while the value 5% is used for both the "left" and "right" padding, so the order going clockwise is: top [and hence also bottom] (3em) → right [and hence also left] (5%); there is no "→ bottom" nor is there "→ left" in this case because the "bottom" and "left" padding have already been defined. The same reasoning also applies to style="padding: 1em 20px 8% 9em;", and style="padding: 3%;". footnote for an example with an explanation).

This same order is also used elsewhere, such as when specifying a cell's borders with border-style: .

Setting default cell padding

Use cellpadding= to set the default padding for each cell in a table. If class=wikitable is used then cellpadding is ignored.

The default space between cells can be changed using cellspacing=.

If cellpadding is not used

Wikitext

style="border:1px solid black"
CellCell
CellCell

Produces

style="border:1px solid black"
CellCell
CellCell

{{clear}}

Using cellpadding=10:

Wikitext

cellpadding=10; style="border:1px solid black"
CellCell
CellCell

Produces

cellpadding=10; style="border:1px solid black"
CellCell
CellCell

Using cellpadding=0:

Wikitext

cellpadding=0; style="border:1px solid black"
CellCell
CellCell

Produces

cellpadding=0; style="border:1px solid black"
CellCell
CellCell

Using cellpadding=0 and cellspacing=0:

Wikitext

cellpadding=0; cellspacing=0; style="border:1px solid black"
CellCell
CellCell

Produces

cellpadding=0; cellspacing=0; style="border:1px solid black"
CellCell
CellCell

Individual cell borders

The same CSS used for tables can be used in a cell's format specifier (enclosed in |...|) to put a border around each cell:

Wikitext

style="border-spacing: 2px; border: 1px solid darkgray;"

! style="width: 140px;" | Left

! style="width: 150px;" | Center

! style="width: 130px;" | Right

style="text-align: center;"

| style="border: 1px solid blue;"|

120px

| style="border: 1px solid #777777;"|

120px

| style="border: 1px solid #22AA55;"|

120px

style="text-align: center;"

|Red star

Orange starGreen star

Produces

style="border-spacing: 2px; border: 1px solid darkgray;"

! style="width: 140px;" | Left

! style="width: 150px;" | Center

! style="width: 130px;" | Right

style="text-align: center;"

| style="border: 1px solid blue;"|

120px

| style="border: 1px solid #777777;"|

120px

| style="border: 1px solid #22AA55;"|

120px

style="text-align: center;"

|Red star

Orange starGreen star

Note that only the image cells have individual borders, not the text. The lower hex-colors (such as: #616161) are closer to black. Typically, all borders in a table would be one specific color.

;Border styles

The style='border:' and style='border-style:' properties can accept the following arguments:

style="border-spacing: 5px;"

! Argument

! Cell border

! Additional notes

none

|style="padding: 1em; border-style: none;"|style="border-style: none;"

|style="padding: 1em;"|

solid

|style="padding: 1em; border-style: solid;"|style="border-style: solid;"

|style="padding: 1em;"|

double

|style="padding: 1em; border-style: double;"|style="border-style: double;"

|style="padding: 1em;"|

dashed

|style="padding: 1em; border-style: dashed;"|style="border-style: dashed;"

|style="padding: 1em;"|

dotted

|style="padding: 1em; border-style: dotted;"|style="border-style: dotted;"

|style="padding: 1em;"|

ridge

|style="padding: 1em; border:5px ridge red;"|style="border:5px ridge red;"

|style="padding: 1em;"|3D ridged border

groove

|style="padding: 1em; border:5px groove blue;"|style="border:5px groove blue;"

|style="padding: 1em;"|3D grooved border

inset

|style="padding: 1em; border: 5px inset yellow;"|style="border: 5px inset yellow;"

|style="padding: 1em;"|3D inset border

outset

|style="padding: 1em; border: 5px outset cyan;"|style="border: 5px outset cyan;"

|style="padding: 1em;"|3D outset border

inherit

|style="padding: 1em; border-style: inherit;"|style="border-style: inherit;"

|style="padding: 1em;"|Inherit value from parent

initial

|style="padding: 1em; border-style: initial;"|style="border-style: initial;"

|style="padding: 1em;"|Set to default value

;Borders of a cell using border-top, border-right, border-bottom, border-left

Wikitext

style="border-top: solid;" | style="border-top: solid;"
style="border-top: solid 2px red; border-right: dashed 3px green; border-bottom: double 5px blue; border-left: dotted 6px yellow;" |
border-top: solid 2px red;

border-right: dashed 3px green;

border-bottom: double 5px blue;

border-left: dotted 6px yellow;

Produces

style="border-top: solid;" | style="border-top: solid;"
style="border-top: solid 2px red; border-right: dashed 3px green; border-bottom: double 5px blue; border-left: dotted 6px yellow;" |
border-top: solid 2px red;

border-right: dashed 3px green;

border-bottom: double 5px blue;

border-left: dotted 6px yellow;

;Top, right, bottom, and left borders of a cell using style='border-style:'

To set the left, right, bottom, or top border of a single cell, one may use style='border-style:' which takes between 1 and 4 arguments, each of which is either none, solid, double, dotted, dashed, groove, ridge, inset, outset, inherit, or initial.

These arguments are ordered according to the pattern described here.

For instance, style="border-style: solid none solid none;" where the four parameters correspond respectively to the

{{in5}}'border-style: top right bottom left;'

borders of the cell.

For reasons described after this example, there are many ways to change the following {{em|code}} that would {{em|not}} result in any changes to the table that is actually {{em|displayed}}.

Wikitext

class=wikitable
Top_Left

| style="border-style: solid solid none none;" | Top_Center

| Top_Right

style="border-style: none none solid solid;" | Middle_Left

| style="border-style: none none none none;" | Middle_Center

| style="border-style: solid solid none none;" | Middle_Right

Bottom_Left

| style="border-style: none none solid solid;" | Bottom_Center

| Bottom_Right

Produces

class=wikitable
Top_Left

| style="border-style: solid solid none none;" | Top_Center

| Top_Right

style="border-style: none none solid solid;" | Middle_Left

| style="border-style: none none none none;" | Middle_Center

| style="border-style: solid solid none none;" | Middle_Right

Bottom_Left

| style="border-style: none none solid solid;" | Bottom_Center

| Bottom_Right

Note, however, that in the following table, none of the central cell's (i.e. Middle_Center's) borders are removed despite the code style="border-style: none none none none;":

Wikitext

class=wikitable
Top_LeftTop_CenterTop_Right
Middle_Left

| style="border-style: none none none none;" | Middle_Center

| Middle_Right

Bottom_LeftBottom_CenterBottom_Right

Produces

class=wikitable
Top_LeftTop_CenterTop_Right
Middle_Left

| style="border-style: none none none none;" | Middle_Center

| Middle_Right

Bottom_LeftBottom_CenterBottom_Right

This happens because the code class="wikitable" places a border (top, right, bottom, and left) around {{em|every}} cell in the table so that, for instance, there are actually {{em|two}} borders between the cells "Middle_Center" and "Middle_Right".

So to remove the border between cells "Middle_Center" and "Middle_Right", it is necessary to remove both the right border of "Middle_Center" {{em|and}} the left border of "Middle_Right":

Wikitext

class=wikitable
Top_LeftTop_CenterTop_Right
Middle_Left

| style="border-style: none none none none;" | Middle_Center

| style="border-style: none none none none;" | Middle_Right

Bottom_LeftBottom_CenterBottom_Right

Produces

class=wikitable
Top_LeftTop_CenterTop_Right
Middle_Left

| style="border-style: none none none none;" | Middle_Center

| style="border-style: none none none none;" | Middle_Right

Bottom_LeftBottom_CenterBottom_Right

To remove selected external borders of a wikitable, both remove them from the adjacent cells and begin the whole table with code like {| class="wikitable" style="border: none;".

Note that replacing {| class="wikitable" with

{{in5}}{| style="border-collapse: collapse;"

has the effect of removing all cell borders that would otherwise appear by default around every cell in the table.

With this change, you must {{em|insert}} a {{em|single}} cell border between two adjacent cells rather than remove {{em|two}} cell borders.