Template:Float/doc: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1:
{{Documentation subpage}}
<!-- PLEASEPlease ADDadd CATEGORIEScategories ATto THEthe BOTTOM/doc OF THIS PAGEsubpage, and INTERWIKISinterwikis at Wikidata IN(see WIKIDATAWikipedia:Wikidata) -->
{{Notice |Take care when using this template in navboxes to ensure that whatever it is used to float (e.g. an image) does not float over other elements or text if/when the navbox is resized. To align centered lists in a navbox with an image, see the [[#Alternatives for navigational boxes|alternatives for navigational boxes]] section below. For aligning text in general, see {{tl|align}}. For floating images, boxes, and other elements, see {{tl|stack}}.}}
 
== Description ==
UseIt {{tl|float}}is used to "float"position items{{spacedtext ndash}}i.e.or positionelements them{{spacedto ndash}}sothe theyrightmost/leftmost doof nota affectpage/area, without changing the alignment or formatting of other itemstext (suchand as text)elements nearby.
 
For aligning text in general, see {{tl|align}}. For floating images, boxes, and other elements, see {{tl|stack}}.
 
== Usage ==
These are the standard usage:
* <code><nowiki>{{float|</nowiki>{{bigger|{{smallcaps|item}}}}}}</code> floats {{smallcaps|item}} on the righthand edge of a page/area.
* <code><nowiki>{{float|left|</nowiki>{{bigger|{{smallcaps|item}}}}}}</code> floats {{smallcaps|item}} on the lefthand edgerightmost of a page/area.
* <code><nowiki>{{float |top= |right= |bottom= |left= |width= |</nowiki>{{bigger|{{smallcaps|item}}}}}}</code> floats {{smallcaps|item}} on the leftmost of a page/area.
 
More configuration:
* <code><nowiki>{{float |width= |height= |top= |right= |bottom= |left= |</nowiki>{{bigger|{{smallcaps|item}}}}}}</code>
 
<code>{{bigger|{{smallcaps|item}}}}</code> is required. You must specify what text or element to float or it will throw an error.
 
All parameters are optional. The parameters {{para|width}} and {{para|height}} are to indicate the width/height of the <code><nowiki><div></nowiki></code> element. <!--Unnecessary?: Note that if any values other than zero for ''top'' and ''right'' are required, they need to be specified.-->
 
The optional parameters {{para|top}}, {{para|right}}, {{para|bottom}} and {{para|left}} are to indicate how far from their respective positions the item is to be positioned.
 
Any established HTML/CSS units may be used, for example, <code><nowiki>{{float |top=2.0em |left=2px |width=10em | the content to float}}</nowiki></code>.
 
=== Beware ===
Beware when using this template in navboxes. Please ensure whatever it floats (e.g. an image) does not float over other elements or text, even after the navbox is resized.
 
To align centered lists in a navbox with an image, see the [[#Alternatives for navigational boxes|alternatives for navigational boxes]] section below.
{{para||{{bigger|{{smallcaps|item}}}}}} is the only required parameter. The optional parameters ''top'', ''right'', ''bottom'' and ''left'' indicate how far from their respective positions the item is to be positioned. The ''width'' of the item may also be specified. Any established HTML/CSS units may be used so long as they are specified (for example, <code><nowiki>{{float |top=2.0em |left=2px |width=10em |Blah}}</nowiki></code>). <!--Unnecessary?: Note that if any values other than zero for ''top'' and ''right'' are required, they need to be specified.-->
 
== Examples ==
Note how the links in the second two examples are centered relative to the whole template, unlike those in the first example.
 
=== Example 1 (without float) ===
One-lineThis is a [[Template:Navbox|navbox]] using its image parameter:
{{Navbox
| name = Float/doc
Line 31 ⟶ 46:
* [[List of weapons of the Japanese Navy|Weapons]]
}}
{{Hidden begin |showhide=left |title=CodeThe forcode Exampleused 1in the above example}}
<pre>
{{Navbox
Line 49 ⟶ 64:
{{Hidden end}}
 
=== Example 2 (with float) ===
SameWe navbox usinguse {{tlf|float}} instead of the navbox's image parameter:
{{Navbox
| name = Float/doc
Line 56 ⟶ 71:
| title = [[Imperial Japanese Navy]]
| listclass = hlist
| list1 = {{float|top=-0.1em|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
* [[Imperial Japanese Navy admirals|Admirals]]
* [[Battles of the Imperial Japanese Navy|Battles]]
Line 63 ⟶ 78:
* [[List of weapons of the Japanese Navy|Weapons]]
}}
{{Hidden begin |showhide=left |title=CodeThe forcode Exampleused 2in the above example}}
<pre>
{{Navbox
Line 70 ⟶ 85:
| title = [[Imperial Japanese Navy]]
| listclass = hlist
| list1 = {{float|top=-0.1em|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
* [[Imperial Japanese Navy admirals|Admirals]]
* [[Battles of the Imperial Japanese Navy|Battles]]
* [[List of ships of the Japanese Navy|Ships]]
* [[List of aircraft of the Japanese Navy|Aircraft]]
* [[List of weapons of the Japanese Navy|Weapons]]
}}
</pre>
{{Hidden end}}
 
=== Example 3 (with float and custom values) ===
We use {{tlf|float}} with a custom value of {{para|top}} this time:
{{Navbox
| name = Float/doc
| state = uncollapsed
| title = [[Imperial Japanese Navy]]
| listclass = hlist
| list1 = {{float|top=0.5em|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
* [[Imperial Japanese Navy admirals|Admirals]]
* [[Battles of the Imperial Japanese Navy|Battles]]
* [[List of ships of the Japanese Navy|Ships]]
* [[List of aircraft of the Japanese Navy|Aircraft]]
* [[List of weapons of the Japanese Navy|Weapons]]
}}
{{Hidden begin |showhide=left |title=The code used in the above example}}
<pre>
{{Navbox
| name = Float/doc
| state = uncollapsed
| title = [[Imperial Japanese Navy]]
| listclass = hlist
| list1 = {{float|top=0.5em|[[File:Naval Ensign of Japan.svg|24px|border|Naval Ensign of Japan]]}}
* [[Imperial Japanese Navy admirals|Admirals]]
* [[Battles of the Imperial Japanese Navy|Battles]]
Line 81 ⟶ 127:
 
=== Alternatives for navigational boxes ===
SameWe navbox usinguse its image parameter and liststyle with padding-left set to the image width:
{{Navbox
| name = Float/doc
Line 96 ⟶ 142:
* [[List of weapons of the Japanese Navy|Weapons]]
}}
{{Hidden begin |showhide=left |title=CodeThe forcode thisused alternativein navigationalthe boxabove example}}
<pre>
{{Navbox
Line 120 ⟶ 166:
* {{tl|clear}}
 
 
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox other||
| <!-- ADD CATEGORIES HERE, and INTERWIKIS IN WIKIDATA -->
<!-- Add categories below this line, and interwikis at Wikidata -->
[[{{ns:Category}}:Positioning templates]]
}}</includeonly>
Anonymous user