Help:Navboxes

From the Dixwell Dossier
Jump to: navigation, search
Wikimedia Meta logoThis page was originally located at Wikimedia Meta. Text on Meta is available under Creative Commons Attribution-ShareAlike (unless otherwise noted).

Content on a wiki page can be made collapsible with JavaScript (acting on CSS classes and manipulating their display properties), in the form of navigational boxes (or navboxes for short).

This functionality (unlike sortable tables) is not native to MediaWiki. It depends on the code added by admins to their project's Common.js file; on the Dixwell Dossier, this is provided by way of Navbox.css and Navbox.js.

[edit]

To make any table collapsible, add a special class collapsible.

For example, the following table is defined with {| class="collapsible wikitable":

Always displayed header
Optionally displayed text; optionally displayed text

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="wikitable collapsible collapsed"

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 wikitable" 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

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 Wikipedia.

For existing table one can simply add collapsible class. If the table has several columns, 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.

Sortable collapsible table

Sortable table inside a collapsible table:

initially expanded initially collapsed
class="collapsible" class="collapsible collapsed"
numbers
name number
a 123
b 6
c 45

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"
name number
a 123
b 6
c 45

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
Wikipedia favicon This page uses material from Wikipedia:NavFrame, originally located at Wikipedia. The list of original authors can be found in the page history there.
The text of Wikipedia is available under Creative Commons BY-SA-3.0 and the GNU Free Documentation License.

The <div> tag can also be used to construct navboxes, using three classes: NavFrame, NavHead, and NavContent.

Examples

Basic, unhidden content is presented in this way:

<div class="NavFrame">
  <div class="NavHead">[... This is the title of your collapsible content ...]</div>
  <div class="NavContent">
    [... The content you want to hide goes here ...]
  </div>
</div>

To hide the content, use this trick:

<div class="NavFrame collapsed">
  <div class="NavHead">[... This is the title of the hidden content ...]</div>
  <div class="NavContent">
    [... This content is initially hidden ...]
  </div>
</div>

The header and content can also be swapped thus:

<div class="NavFrame">
  <div class="NavContent">
    [... The content you want to hide goes here ...]
  </div>
  <div class="NavHead">[... This is the caption below your collapsible content ...]</div>
</div>

When the title is too long...

<div style="width: 20em">
<div class="NavFrame">
  <div class="NavHead">[... This is the title of your collapsible content ...]</div>
  <div class="NavContent">
    [... The content you want to hide goes here ...]
  </div>
</div>
</div>

you can use height:auto for the NavHead style, and a dummy element to leave space for the "show/hide" link:

<div style="width: 20em">
<div class="NavFrame" style="width: 20em">
  <div class="NavHead" style="height:auto">
    <div class="hack-to-leave-space" style="float:right"><nowiki>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</nowiki></div>
     [... This is the title of your collapsible content ...]
  </div>
  <div class="NavContent">
    [... The content you want to hide goes here ...]
  </div>
</div>
</div>

See also