Help:列表
![]() |
注意:當您編輯本頁面時,即同意以CC0協議授權您的貢獻。您可以在公有領域帮助页面找到更多信息。 此頁面的部分舊修訂版本是在知识共享署名-相同方式共享(CC BY-SA)許可下导入的。 只有新的貢獻採用公有領域授權。 |
![]() |
本页面将帮助你在MediaWiki中创建列表。
基础列表
MediaWiki 提供了三种类型的列表:无序列表(unordered lists)、有序列表(ordered lists)和定义(definition)列表。
基本用法
- 无序列表
- 每个项目都在以星号
*
开头的新行上,例如* 项目
。 - 有序列表
- 每个项目都在以井号
#
开头的新行上,例如# 项目
。 - 定义列表
- 每个项目都有两个部分:术语和描述。
- 术语位于以分号
;
开头的新行上,例如; 术语
。 - 描述跟在冒号
:
后面的同一行,例如; 术语 : 描述
, - 或者描述以冒号
:
开头,例如: description
(每个术语可以有多个描述,每个描述都以新行上的冒号开头)。
进阶用法
在下表中,您将找到这两种方法的一些示例:
维基文本 | 渲染 |
---|---|
* 列表就是这么创建的: ** 第一行 * 第一层 ** 第二层 *** 第三层 |
|
* 新的一行 * 列表 标记这是列表最后一行。 当然 * 你可以 * 再创建一行 |
标记这是列表最后一行。 当然
|
# 数字列表也不错 ## 很整齐 ## 容易理解 |
|
* 您也可以 ** 像这样<br>在列表内<br>分行 |
|
; 描述或定义列表 ; 术语 : 定义 ; 分号项 : 冒号定义 |
|
; 混合定义列表 ; 第1项 : 定义 :; 子项目1的术语 :: 两个冒号的定义 :; 子项目2 : 冒号的定义 ; 项目2 : 返回主列表 |
|
* 或创建混合列表 *# 并将它们嵌套 *#* 像这样 *#*; 定义 *#*: 工作: *#*; 苹果 *#*; 香蕉 *#*: 水果 |
|
列表的复数行
为简单起见,wiki标记中的列表项不能超过一个段落。以下空行将结束列表并重置有序列表上的计数器。分离无序列表项通常不会产生明显影响。
可以使用HTML标记在列表中强制使用段落。
如果您想放置多行文本,请添加两个换行符(<br /><br />
),您将获得所需的效果。
将文本换行<p>...</p>
会将该文本呈现在新段落中,该段落在呈现时将从自己的行开始。
在子项之后继续列表项
In HTML, a list item may contain several sublists, not necessarily adjacent; thus there may be parts of the list item not only before the first sublist, but also between sublists, and after the last one. However, in wiki-syntax, sublists follow the same rules as sections of a page: the only possible part of the list item not in sublists is before the first sublist.
In the case of an unnumbered first-level list in wikitext code this limitation can be overcome by splitting the list into multiple lists; indented text between the partial lists may visually serve as part of a list item after a sublist; however, this may give, depending on CSS, a blank line before and after each list, in which case, for uniformity, every first-level list item could be made a separate list.
Numbered lists illustrate that what should look like one list may, for the software, consist of multiple lists; unnumbered lists give a corresponding result, except that the problem of restarting with 1 is not applicable.
维基文本 | 渲染 |
---|---|
<ol>
<li>列表项 A1
<ol>
<li>列表项 B1</li>
<li>列表项 B2</li>
</ol>继续列表项 A1
</li>
<li>列表项 A2</li>
</ol>
|
|
vs. | |
#列表项A1 ##列表项B1 ##列表项B2 #:继续列表项A1 #列表项A2 |
|
再深一层,子列表项在子子列表之后继续,会得到更多的空行;但是,第一级列表的延续不受影响:
维基文本 | 渲染 |
---|---|
#列表项A1 ##列表项B1 ###列表项C1 ##:继续列表项B1 ##列表项B2 #列表项A2 |
|
可以在闭合的有序项中嵌入无序项符号:
维基文本 | 渲染 |
---|---|
# list item A #* nested bullet A1 #* nested bullet A2 # continuing list item B #* nested bullet B1 #* nested bullet B2 |
|
切换列表类型
Per list
The list type (which type of marker appears before the list item) can be changed in CSS by setting the list-style-type property:
Wikitext | Rendering |
---|---|
<ol style="list-style-type:lower-roman">
<li>About the author</li>
<li>Foreword to the first edition</li>
<li>Foreword to the second edition</li>
</ol>
|
|
<ol style="list-style-type:lower-alpha">
<li>About the author</li>
<li>Foreword to the first edition</li>
<li>Foreword to the second edition</li>
</ol>
|
|
Site-wide
The standard #, ##, ### wikitext can be used alongside CSS in MediaWiki:Common.css to produce the usual system of numbered lists (1, 2, 3; then a, b, c; then i, ii, iii):
ol {
list-style-type: decimal;
}
ol li > ol {
list-style-type: lower-alpha;
}
ol li > ol li > ol {
list-style-type: lower-roman;
}
The first ol
above is the default, so not necessary unless some other list-style-type is required.
Wikitext | Rendering |
---|---|
#list item A1 ##list item B1 ###list item C1 ###list item C2 ##list item B2 #list item A2 |
|
Extra indentation of lists
In a numbered list in a large font, some browsers do not show more than two digits, unless extra indentation is applied (if there are multiple colons: for each colon). This can be done with CSS:
ol { margin-left: 2cm}
or alternatively, like below.
Wikitext | Rendering | Comments |
---|---|---|
:#abc :#def :#ghi |
|
A list of one or more lines starting with a colon creates a description list without definition terms, and with the items as definition descriptions, hence indented. However, if the colons are in front of the codes "*" or "#" of an unordered or ordered list, the list is treated as one definition description, so the whole list is indented. |
<ul>
<ol>
<li>abc</li>
<li>def</li>
<li>ghi</li>
</ol>
</ul>
|
|
MediaWiki translates an unordered list (ul) without any list items (li) into a div with a style="margin-left: 2em" , causing indentation of the contents. This is the most versatile method, as it allows starting with a number other than 1, see below.
|
<ul>
#abc
#def
#ghi
</ul>
|
|
Like above, with the content of the "unordered list without any list items", which itself is an ordered list, expressed with # codes. The HTML produced, and hence the rendering, is the same. This is the recommended method when starting the list at 1. |
Specifying a starting value
Specifying a starting value is possible with HTML syntax.
<ol start="9">
<li>Amsterdam</li>
<li>Rotterdam</li>
<li>The Hague</li>
</ol>
|
|
Or:
<ol>
<li value="9">Amsterdam</li>
<li value="8">Rotterdam</li>
<li value="7">The Hague</li>
</ol>
|
|
Comparison with a table
Apart from providing automatic numbering, the numbered list also aligns the contents of the items, comparable with using table syntax:
{| |- | align=right | 9.|| Amsterdam |- | align=right | 10.|| Rotterdam |- | align=right | 11.|| The Hague |}
gives:
9. | Amsterdam |
10. | Rotterdam |
11. | The Hague |
This non-automatic numbering has the advantage that if a text refers to the numbers, insertion or deletion of an item does not disturb the correspondence.
Multi-column lists
See also Template:Col-begin, Template:Col-break, Template:Col-end.
Multi-column bulleted list
<div style="column-count:2">
* apple
* carpet
* geography
* mountain
* nowhere
* postage
* ragged
* toast
</div>
gives:
- apple
- carpet
- geography
- mountain
- nowhere
- postage
- ragged
- toast
<div style="column-count:3">
* apple
* carpet
* geography
* mountain
* nowhere
* postage
* ragged
* toast
</div>
gives:
- apple
- carpet
- geography
- mountain
- nowhere
- postage
- ragged
- toast
Multi-column numbered list
<div style="column-count:3">
#apple
#carpet
#geography
#mountain
#nowhere
#postage
#ragged
#toast
</div>
gives:
- apple
- carpet
- geography
- mountain
- nowhere
- postage
- ragged
- toast
Below a starting value is specified, with HTML-syntax (for the first column either wiki-syntax or HTML-syntax can be used).
In combination with the extra indentation explained in the previous section:
{| valign="top"
|-
|<ul><ol start="125"><li>a</li><li>bb</li><li>ccc</li></ol></ul>
|<ul><ol start="128"><li>ddd</li><li>ee</li><li>f</li></ol></ul>
|}
gives
|
|
Using m:Template:multi-column numbered list the computation of the starting values can be automated, and only the first starting value and the number of items in each column except the last has to be specified. Adding an item to, or removing an item from a column requires adjusting only one number, the number of items in that column, instead of changing the starting numbers for all subsequent columns.
{{Multi-column numbered list|125|a<li>bb<li>ccc|3|<li>ddd<li>ee<li>f}}
gives:
|
|
{{Multi-column numbered list|lst=lower-alpha|125|a<li>bb<li>ccc|3|<li>ddd<li>ee|2|<li>f}}
gives:
|
|
|
{{Multi-column numbered list|lst=lower-roman|125|a<li>bb<li>ccc|3|<li>ddd<li>ee|2|<li>f}}
gives:
|
|
|
{{Multi-column numbered list|lst=disc||a<li>bb<li>ccc||<li>ddd<li>ee||<li>f}}
gives:
|
|
|
Streamlined style or horizontal style
It is also possible to present short lists using very basic formatting, such as:
''Title of list:'' example 1, example 2, example 3
Title of list: example 1, example 2, example 3
This style requires less space on the page, and is preferred if there are only a few entries in the list, it can be read easily, and a direct edit point is not required. The list items should start with a lowercase letter unless they are proper nouns.
Tables
A one-column table is very similar to a list, but it allows sorting. If the wikitext itself is already sorted with the same sortkey, this advantage does not apply. A multiple-column table allows sorting on any column.
See also When to use tables.
Changing unordered lists to ordered ones
With the CSS
ul { list-style: decimal }
unordered lists are changed to ordered ones. This applies (as far as the CSS selector does not restrict this) to all ul-lists in the HTML source code:
- those produced with *
- those with
<ul>
in the wikitext - those produced by the system
Since each special page, like other pages, has a class based on the pagename, one can separately specify for each type whether the lists should be ordered. See also User contributions and What links here.
However, it does not seem possible to make all page history lists ordered (unless one makes all lists ordered), because the class name is based on the page for which the history is viewed.
参见
- Wikipedia help page about lists
- Module:Sort definition list - A Scribunto module that allows to sort definition lists by the term defined, useful on multilingual wikis.