Adapted from Resource Loader Modules documentation:
For certain situations, having collapsible content areas defined in an article or template may be useful for saving space or improving usability of information in long articles. These may be customized by using certain custom attributes, and combinations of class and id attributes.
- Default toggle link: Add
mw-collapsible
to an element'sclass
attribute with some content and save the page. The inner content of this element will be treated as collapsible content. Prepended to the element, before the collapsible content, is a toggle-link with a localized label (collapsible-expand, collapsible-collapse). To set the initial state to collapsed, addmw-collapsed
to theclass
attribute. - Custom label (HTML5 only): Using the
data-collapsetext
anddata-expandtext
attributes defines custom text for the toggle labels added by the script. This retains the default behavior of the script, but only changes the text used for the toggle links. - Remote toggle: To completely replace the toggle link and explicitly define the content area to be collapsed (which may be different from where the toggle link is placed), add an
id
atribute with a value containing amw-customcollapsible-
prefix for the collapsible element, and a correspondingclass
attribute with amw-customtoggle-
prefix for the toggle link.
舉例[ | ]
Default toggle link[ | ]
輸入:
{| class="infobox"
! Foo
| Bar
|-
! Lorem
| Ipsum
|-
! More info
|<!--
-->
{| class="wikitable mw-collapsible mw-collapsed" style="width: 100%;"
! Head
! Top
|-
| Cell
| content
|-
| This table is collapsible
| Because it has the "mw-collapsible" class
|-
| It was initially hidden, because it
| had the "mw-collapsed" class
|}<!--
-->
|-
|}
<div class="toccolours mw-collapsible" style="color:#000;width: 400px;">
This is text is collapsible.
</div>
輸出:
Foo | Bar | ||||||||
---|---|---|---|---|---|---|---|---|---|
Lorem | Ipsum | ||||||||
More info |
|
This is text is collapsible.
Custom Label[ | ]
輸入:
{| class="wikitable mw-collapsible mw-collapsed" data-expandtext="+" data-collapsetext="-"
! Column 1 !! Column 2 !! Column 3
|-
| 1 || 2 || 3
|-
| 4 || 5 || 6
|-
| 7 || 8 || 9
|}
<div class="mw-collapsible mw-collapsed" data-expandtext="Open" data-collapsetext="Close" style="width:300px;">
This text is not hidden
<div class="mw-collapsible-content">
This text is all hidden
And is only shown
When it is uncollapsed.
</div></div>
輸出:
Column 1 | Column 2 | Column 3 |
---|---|---|
1 | 2 | 3 |
4 | 5 | 6 |
7 | 8 | 9 |
This text is not hidden
This text is all hidden
And is only shown
When it is uncollapsed.
Remote toggle[ | ]
輸入:
<div class="mw-customtoggle-myDivision" style="color:#700">Click here to toggle the element</div>
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision">
<div class="mw-collapsible-content">Lorem ipsum dolor sit amet...</div>
</div>
<div class="mw-customtoggle-myDivision" style="color:#070">Clicking will toggle it also!</div>
輸出:
Click here to toggle the element
Lorem ipsum dolor sit amet...
Clicking will toggle it also!
Removing Brackets From Toggle[ | ]
The following style rule may be added to the wiki's stylesheet to hide the brackets in the default or custom label toggle links:
span.mw-collapsible-bracket {
display: none;
}