- Wikipedia:NavFrame
-
The use of NavFrame for tables has been deprecated in favor of collapsible tables since September 2007. NavFrame is still useful for non-table content. Documentation for dynamic navigation boxes.
Dynamic navigation boxes use a combination of CSS and Javascript to make collapsible navigation boxes. The technical parts comprise style sheet declarations in MediaWiki:Common.css, and Javascript code in MediaWiki:Common.js.
Example (click "show" or "hide" to see the good bits):
Soviet armoured fighting vehicles of World War II Tankettes Amphibious tanks Fast tanks Medium tanks Heavy tanks Light tanks Anti-aircraft guns Heavy Aerosans Armored Artillery tractors Artillery tractors S-2 Stalinets · S-60 Stalinets · S-65 Stalinets · Kommunar · STZ-3 · STZ-5 · YA-12Experimental and improvised vehiclesExperimental Improvised Contents
How to use
The basic concept here is to use the div element within a Wiki article's markup code to identify certain content (which we'll call the "details" here) that we want the user to be able to "show" or "hide". The markup code used to achieve this effect comprises three main classes:
NavFrame, NavHead, NavContent
.The underlying implementation uses Javascript to add a "show" or "hide" link in the
NavHead
part, and to turn the visibility of theNavContent
part on or off. In web browsers that do not support Javascript, or where Javascript is disabled, the content will always be displayed, and the "show"/"hide" links will not be present.The default behavior of this code will initially "show" the details, as well as a link to "hide" the details. To reverse the default behavior, so that the details are initially hidden, use
class="NavFrame collapsed"
(instead ofclass="NavFrame"
) in the outer div element. Do not addstyle="display:none;"
to the NavContent element, because that will make it impossible for users without Javascript to see the content.Simple example
You will need to create three
div
elements:<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>
[... This is the title of your collapsible content ...][... The content you want to hide goes here ...]
To initially hide the content do this:<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>
[... This is the title of the hidden content ...][... This content is initially hidden ...]
Mixed classes example
You can even apply other classes along with these, making a more styled design rather than if you were to use the standard classes:
<div class="messagebox standard-talk NavFrame"> <div class="somerandomclass NavHead"> [... This is the title; it does not have to be plain text, you can get creative here ...]</div> <div class="NavContent anotherclass"> [... The content you want to hide goes here ...] </div> </div>
If you swap the order of the two inner
div
elements, then you can get an always-visible caption below optionally-hidden content, instead of an always-visible heading above optionally-hidden content:<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>
[... The content you want to hide goes here ...]
[... This is the caption below your collapsible content ...]If the title doesn't fit on one line
If the title is too long, then the formatting is very bad:
<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>
[... This is the title of your collapsible content ...][... The content you want to hide goes here ...]
To correct this, you need to add
height: auto
to the style of theNavHead
div
, 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"> </div> [... This is the title of your collapsible content ...] </div> <div class="NavContent"> [... The content you want to hide goes here ...] </div> </div> </div>
[... This is the title of your collapsible content ...]
[... The content you want to hide goes here ...]
Collapsible tables
Main page: Help:CollapsingThe initial state of any collapsible content can be controlled using a "collapsible table", because it also allows a table with only one element with content, and a header.
Left-alignment
To have things lined up to the left, add in this line of code
style="text-align:left"
to the first (or whichever) <div> you want the text inside aligned to the left.
Left-alignmentContent added here. See how nicely it lines up to the left, instead of being centered? Far easier to read for many things.
Limitations
Currently, the three
Nav*
classes apply styles of their own. When mixing classes, this causes some of the Nav styles to override other styles (in the above example, NavFrame is overriding the styles from.messagebox.standard-talk
).This limitation does not affect collapsible tables.
Accessibility
All browsers from Internet Explorer 5.5 and on (IE6/7/8, Firefox, Safari/Chrome/KHTML, Opera 8/9, etc.) that support JavaScript will properly collapse the elements.
Internet Explorer 5 and browsers which do not support JavaScript will render the elements without the [hide/show] links and will not collapse them.
Templates
- Template:Hidden
- Template:Hidden_begin
Navigation templates comparison Collapsible Header color Image Groups Style (body)
parameter/sExamples {{Navbox}} collapsible navbox Left/right of body Yes Yes - {{Solar System}}
- {{United States Congress}}
{{Navbox with collapsible groups}} collapsible navbox Left/right of body and/or in each list Yes Yes - {{Scouting}}
- {{University of Michigan}}
{{Navbox with columns}} collapsible navbox Left/right of columns No Yes - {{Current U.S. Senators}}
- {{Historical regions of the Czech Republic}}
{{Navbox years}} collapsible navbox No No No - {{Wimbledon tournaments}}
Collapsible attributes Type CSS classes Javascript Collapses when Custom
initial stateNesting Collapsible tables collapsible Defined in Common.js 2 or more autocollapse on page Yes Yes Categories:- Navigational boxes
Wikimedia Foundation. 2010.