Help:Collapsing
From Meta, a Wikimedia project coordination wiki
Content can be made collapsible with JavaScript (acting on CSS classes and manipulating their display properties).
This functionality (unlike sortable tables) is not part of MediaWiki. It depends on the code added by admins to the project's MediaWiki:Common.js.
[edit] Collapsible table
To make any table collapsible, add a special class collapsible
For example, the following table is defined with {| class="collapsible prettytable":
| Always displayed header |
|---|
| Optionally displayed text; optionally displayed text |
[edit] Initial state
Collapsible table is initially expanded by default.
You can change this with two additional special classes:
- autocollapse: table will be collapsed if there are more than 2 collapsible tables on the page,
- collapsed: table will be initially collapsed.
Example: {|class="prettytable collapsible collapsed"
| Always displayed header |
|---|
| Initially hidden text. |
[edit] Table width
Since usually the natural width of the header is smaller than of the main content, the table' width will increase after expanding and it will "jump" around. (Also, even if the header would fit in the width of the browser window, the layout engine might divide it over two lines.) It is ugly in itself and inconvenient if you want only to have a quick look at the hidden content and then collapse it again without having to hunt the link with cursor in between. This is prevented by explicitly setting table's width, which then remains the same in the collapsed and expanded state.
Compare this to the first example: {| class="collapsible prettytable" style="width:34em"
| Always displayed header, table has width:34em |
|---|
| optionally displayed text: you can see it doesn't matter at all that this is so much longer, table width has been set at 34em |
[edit] Usage
For content that is not a table one can create a table with only one element with content, and a header. However there's a table-less, purely DIV-based solution available on the Wikipedia - see #Collapsible DIV below.
For existing table one can simply add collapsible class. If the table has several colums, it might be a good idea to add a heading row consisting of one cell otherwise the link will be in the first one. Sometimes an easy solution is to put the whole table as element inside another table (see example below); however this is bad from the webdesign and usability viewpoint.
[edit] Sortable collapsible table
Sortable table inside a collapsible table:
| initially expanded | initially collapsed | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| class="collapsible" | class="collapsible collapsed" | ||||||||||||||||||||
|
|
If the sortable table is itself made collapsible the positioning of the hide/show button is a bit odd:
| initially expanded | initially collapsed | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| class="wikitable sortable collapsible" | class="wikitable sortable collapsible collapsed" | ||||||||||||||||
|
|
[edit] Personal customization
Registered users can edit their own monobook.js to change these variables (default values are shown):
autoCollapse = 2 //how many collapsible tables on the page before autocollapse works var collapseCaption = 'hide' //text of the [hide] link var expandCaption = 'show' //text of the [show] link
[edit] Collapsible DIV
This functionality is not implemented on Meta, for information see w:Wikipedia:NavFrame.
[edit] See also
- Help:Footnotes - another way of separating "main" and "supplementary" content.