Help:使用維基標記式語言增修表格/5
一般而言,我們建議表格僅以維基百科的預設格式設定即可。然而在部分情況下,您會需要使用更複雜的格式,這些格式可由CSS來進行實作。每個表格格子的呈現方式都在格子內容之前增加style=" " |
來加以控制。同樣,CSS格式也可以在表格標題與表頭處以同樣方式進行添加。
對於格子內容| style="" | R1C1 | style="" | R1C2 | style="" | R1C3
|
|
對於表頭! style="" | 表頭C1 ! style="" | 表頭C2 ! style="" | 表頭C3
|
任何的CSS屬性可以在style=" " |
進行添加。
屬性 | 意義 | 範例 |
---|---|---|
background | 填滿背景與指定背景顏色 | background:yellow
|
color | 文字顏色 | color:blue
|
width | 格子寬度 | width:100px
|
border-width | 邊界寬度 | border-width:3px
|
text-align | 格子內的文字排列 | text-align:center
|
如同上述範例所列,以下就示範將這些屬性套用至特定的表格格子:
{| class="wikitable" |+ 說明:部分格子為黃色。 |- ! Header1 ! Header2 ! Header3 |- | style="background: yellow" | R1C1 | R1C2 | style="background: yellow" | R1C3 |- | R2C1 | style="background: yellow" | R2C2 | R2C3 |}
這將會產生如下表格:
表頭1 | 表頭2 | 表頭3 |
---|---|---|
R1C1 | R1C2 | R1C3 |
R2C1 | R2C2 | R2C3 |
CSS attributes can be added to the whole table by editing the first line of the table using {| style=" "
in the first line. Similarly, attributes can be added to a row using |- style=" "
The example below would fill the whole table yellow.
{| class="wikitable" style="background: yellow"
All of these formatting options should be used sparingly. Tables in crazy colours are hard to read.
隱藏式註解
In complicated tables, sometimes hidden comments can be useful to explain formatting. These hidden comments are only visible when editing the page, not when reading it normally. Comments can be added by placing them between <!--
and -->
.
| R1C1 || R1C2 ||R1C3 <!-- Hidden comment to explain this row -->