Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Help:Collapsing tables and more

From Wikipedia, the free encyclopedia
Wikipedia project page
This page is about how to collapse content when editing Wikipedia pages. For the Manual of Style on collapsing content, seeMOS:COLLAPSE.
This help page is ahow-to guide.
It explains concepts or processes used by the Wikipedia community. It is not one ofWikipedia's policies or guidelines, and may reflect varying levels ofconsensus.

Acollapsible element contains a toggle a reader can use to show or hide the element's content. Elements are made collapsible by adding themw-collapsible class, or alternatively by using the{{Collapse}} template, or its variants{{Collapse top}} and{{Collapse bottom}}.

Use of these features in article content is governed by the guidelinesWikipedia:Manual of Style § Scrolling lists and collapsible content generally, and more specifically byWikipedia:Spoiler.

Collapsible tables

[edit]

Themw-collapsible class can make any element collapsible, but tables are particularly simple to make collapsible. Adding themw-collapsible class to a table automatically positions the toggle, and selects which parts to collapse.

A common use is to make a collapsible layout table, which always displays an introduction or summary, but hides the rest of the content from immediate view. The introduction or summary is in the first row, and the content is in subsequent rows. The content is then easily accessible by using the 'show' button.

In the examples below, the use of the classwikitable is merely for appearance; it is not needed formw-collapsible to function.

Code enteredOutput produced
{|role="presentation"class="wikitable mw-collapsible"|<strong>Lorem ipsum</strong>|-| Lorem ipsum dolor sit amet|}
Lorem ipsum
Lorem ipsum dolor sit amet

More complex data tables can also be collapsible.

Code enteredOutput produced
{|class="wikitable mw-collapsible"|+class="nowrap"| Winter Olympic Games|-|!scope="col"| City!scope="col"| Country|-!scope="row"| 1994| Lillehammer|| Norway|-!scope="row"| 1998| Nagano|| Japan|}
Winter Olympic Games
CityCountry
1994LillehammerNorway
1998NaganoJapan

Collapsing by default

[edit]

Just using themw-collapsible class leaves the element expanded by default, but it can be collapsed by the reader. It is also possible to make the element collapsed by default, and optionally expanded by adding other classes along withmw-collapsible. There are several methods for doing this, depending on the situations in which you want the element to collapse. However, content should not be collapsed by default perMOS:DONTHIDE.

"mw-collapsed"

[edit]

Adding themw-collapsed class will cause the element toalways be initially collapsed, no matter what happens around it. It is the simplest method for doing so. Using the examples above:

Code enteredOutput produced
{|role="presentation"class="wikitable mw-collapsible mw-collapsed"|<strong>Lorem ipsum</strong>|-| Lorem ipsum dolor sit amet|}
Lorem ipsum
Lorem ipsum dolor sit amet
{|class="wikitable mw-collapsible mw-collapsed"|+class="nowrap"| Winter Olympic Games|-|!scope="col"| City!scope="col"| Country|-!scope="row"| 1994| Lillehammer|| Norway|-!scope="row"| 1998| Nagano|| Japan|}
Winter Olympic Games
CityCountry
1994LillehammerNorway
1998NaganoJapan

"autocollapse"

[edit]
Using this technique causes the page to reflow/jump around and should generally be avoided.

Adding theautocollapse class causes an element to collapse if there are 2 or more collapsible elements on the page. The example below, therefore, collapses because there are numerous collapsible elements on this page.

Code enteredOutput produced
{|role="presentation"class="wikitable mw-collapsible autocollapse"|<strong>Lorem ipsum</strong>|-| Lorem ipsum dolor sit amet|}
Lorem ipsum
Lorem ipsum dolor sit amet

"innercollapse" and "outercollapse"

[edit]
Using this technique causes the page to reflow/jump around and should generally be avoided.

Using this pair of classes, it is possible to make an element collapsed by default only when it iscontained within a particular outer element. An element with themw-collapsible andinnercollapse classes is collapsed by default if it is contained within an element with theoutercollapse class; otherwise, it is uncollapsed by default. This is mainly useful for templates, which are often nested.

Code enteredOutput produced
{|role="presentation"class="wikitable mw-collapsible innercollapse"| This<code>innercollapse</code> element is|-|<em>uncollapsed</em> by default|}<divclass="wikitable outercollapse"style="padding:1em; background:#ccc;">This is an element with the<code>outercollapse</code> class.{|role="presentation"class="wikitable mw-collapsible innercollapse"| This<code>innercollapse</code> element is|-|<em>collapsed</em> by default|}</div>
Thisinnercollapse element is
uncollapsed by default

This is an element with theoutercollapse class.

Thisinnercollapse element is
collapsed by default

Other notes

[edit]

Tables with captions

[edit]

A table without a caption will collapse to its first row. A tablewith a caption will collapse to its caption, with no rows, therefore no width. Useclass="nowrap" or{{nowrap}} to keep the caption from being squeezed into a vertical column when the table is collapsed.

Code enteredOutput produced
{|class="wikitable sortable mw-collapsible"|+class="nowrap"| Somewhat long table caption! Name!! Score|-| John|| 59|-| Bob|| 72|}
Somewhat long table caption
NameScore
John59
Bob72

Next example uses{{nowrap}} where the end brackets become the wrap point.<style=max-width:Xem; will not work.

Code enteredOutput produced
{|class="wikitable sortable mw-collapsible"|+ {{nowrap|A longer table caption needs to wrap}} for cell phones, etc.! Name!! Score|-| John|| 59|-| Bob|| 72|}
A longer table caption needs to wrap for cell phones, etc.
NameScore
John59
Bob72

Sortable tables

[edit]

Collapsible tables can be combined with thesortable tables functionality without difficulty. However, because the hide/show button is placed withmw-collapsible in the right header cell, its positioning can look a bit peculiar if the cell is not wide enough:

Code enteredOutput produced
{|class="wikitable mw-collapsible sortable"style="width:5em"<!--table width too narrow, on purpose here-->|-! Name!! Score|-| John|| 59|-| Bob|| 72|}
NameScore
John59
Bob72

A possible alternative is to add a caption over the table. See the following example.

Code enteredOutput produced
{|class="wikitable sortable mw-collapsible"|+class="nowrap"| Caption! Name!! Score|-| John|| 59|-| Bob|| 72|}
Caption
NameScore
John59
Bob72

Limitations

[edit]
  • This functionality requires the end-user's browser to haveJavaScript enabled. If JavaScript is disabled, the default behavior is to show the content.

See also

[edit]

Documentation:

Templates:

External links

[edit]
General
technical help
Special
page
-related
Wikitext
Links anddiffs
Media files: images,
videos and sounds
Other graphics
Templates and
Lua modules
Data structure
HTML andCSS
Customisation
and tools
Automated editing
Retrieved from "https://en.wikipedia.org/w/index.php?title=Help:Collapsing_tables_and_more&oldid=1270473377"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp